ค้นหาเว็บไซต์

SharePoint Online: PowerShell เพื่อรับไลบรารีเอกสารทั้งหมด


ข้อกำหนด: PowerShell เพื่อแสดงรายการไลบรารีเอกสารทั้งหมดใน SharePoint Online

จะรับไลบรารีเอกสารทั้งหมดในไซต์ SharePoint Online ได้อย่างไร

หากคุณกำลังจัดการไซต์ SharePoint Online และต้องการรับไลบรารีเอกสารทั้งหมดในไซต์ SharePoint Online มีสองวิธีที่คุณสามารถใช้ได้! โพสต์ในบล็อกนี้จะแสดงวิธีรับไลบรารีเอกสารทั้งหมดใน SharePoint Online

หน้า “เนื้อหาของไซต์” ใน SharePoint จะแสดงรายการและไลบรารีทั้งหมดของไซต์ พร้อมด้วยจำนวนรายการในแต่ละรายการหรือไลบรารี

มาดู SharePoint Online PowerShell เพื่อแสดงรายการไลบรารีเอกสารในไซต์ย่อย (หรือไซต์!)

SharePoint Online PowerShell เพื่อแสดงรายการไลบรารีเอกสาร

ให้ฉันแบ่งปันสคริปต์ที่มีประโยชน์บางอย่างที่คุณต้องการเพื่อแสดงรายการไลบรารีเอกสารทั้งหมดอย่างรวดเร็วสำหรับการรายงานหรือเพื่อวัตถุประสงค์อื่น นี่คือ PowerShell เพื่อรับไลบรารีเอกสารทั้งหมดจากไซต์ SharePoint Online:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
  
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
   
#Get Lists from the web
$Ctx.Load($Ctx.Web.Lists)
$Ctx.executeQuery()
 
#Filter Document Libraries from Lists collection
$Lists = $Ctx.Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}

#Loop through each document library and Get the Title
Foreach ($List in $Lists)
{
    Write-host $List.Title
}

สิ่งนี้ได้รับไลบรารีเอกสารทั้งหมดใน SharePoint Online โดยใช้ PowerShell

PnP PowerShell เพื่อรับไลบรารีเอกสารทั้งหมดและ ID

ฉันจะรับรายการไลบรารีเอกสารใน SharePoint Online โดยใช้ PowerShell ได้อย่างไร นี่คือวิธี PnP PowerShell โดยใช้ Get-PnPList cmdlet:


#Variables
$Site = "https://crescent.sharepoint.com/sites/retail"

#Connect with SharePoint Online
Connect-PnPOnline -Url $Site -Interactive 

#Get all document libraries
$DocLibs = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $false }

#Get ID and Title of the document library
$DocLibs | Select ID, Title

SharePoint Online PowerShell เพื่อแสดงรายการไลบรารีเอกสารทั้งหมดในไซต์คอลเลกชัน

มารวมสคริปต์ลงในฟังก์ชันที่นำมาใช้ซ้ำได้ และเพิ่มการจัดการข้อผิดพลาดเพื่อรับไลบรารีเอกสารจากไซต์คอลเลกชัน SharePoint Online


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Function to Get all documents Libraries in a SharePoint Online Site Collection
Function Get-SPODocumentLibrary($SiteURL)
{
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
   
        #Get the web and Its subsites from given URL
        $Web = $Ctx.web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Lists)
        $Ctx.Load($web.Webs)
        $Ctx.executeQuery()
 
        Write-host -f Yellow "Processing Site: $SiteURL"
 
        #sharepoint online powershell list all document libraries
        $Lists = $Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}

        #Loop through each document library and Get the Title
        Foreach ($List in $Lists)
        {
            Write-host $List.Title
        }
  
        #Iterate through each subsite of the current web and call the function recursively
        ForEach ($Subweb in $Web.Webs)
        {
            #Call the function recursively to process all subsites
            Get-SPODocumentLibrary($Subweb.url)
        }
    }
    Catch {
        write-host -f Red "Error Getting Document Libraries!" $_.Exception.Message
    }
}
  
#Config Parameters
$SiteCollURL="https://crescent.sharepoint.com"
  
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Call the function to get all document libraries in a site collection
Get-SPODocumentLibrary $SiteCollURL

เมื่อต้องการแสดงรายการไลบรารีเอกสารทั้งหมดใน SharePoint Online ด้วย PnP PowerShell ให้ใช้: รับไลบรารีเอกสารทั้งหมดใน SharePoint Online โดยใช้ PnP PowerShell

บทความที่เกี่ยวข้อง