SharePoint Online: Tüm Belge Kitaplıklarını PowerShell Alacak


Gereksinim: SharePoint Online'daki Tüm Belge Kitaplıklarını Listelemek için PowerShell.

SharePoint Çevrimiçi Sitesindeki Tüm Belge Kitaplıkları Nasıl Edinilir?

Bir SharePoint Online sitesini yönetiyorsanız ve tüm belge kitaplıklarını bir SharePoint Online sitesinde almak istiyorsanız kullanabileceğiniz iki yöntem vardır! Bu blog gönderisi, SharePoint Online'daki tüm belge kitaplıklarını nasıl alacağınızı gösterecektir.

SharePoint'teki "Site İçeriği" sayfası, sitenin tüm listelerini ve kitaplıklarını, her liste veya kitaplıktaki öğe sayısıyla birlikte görüntüler.

Bir alt sitedeki (veya sitedeki!) belge kitaplıklarını listelemek için SharePoint Online PowerShell'i görelim.

Belge Kitaplıklarını Listelemek için SharePoint Çevrimiçi PowerShell

Raporlama veya başka amaçlarla tüm belge kitaplıklarını hızlı bir şekilde listelemek için ihtiyaç duyduğunuz bazı kullanışlı komut dosyalarını paylaşmama izin verin. İşte bir SharePoint Online sitesinden tüm belge kitaplıklarını almak için PowerShell:


#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
}

Bu, PowerShell kullanarak SharePoint Online'daki tüm belge kitaplıklarını alır.

PnP PowerShell Tüm Belge Kitaplıklarını ve Kimliklerini Alacak

PowerShell'i kullanarak SharePoint Online'daki belge kitaplıklarının listesini nasıl edinebilirim? İşte Get-PnPList cmdlet'ini kullanan PnP PowerShell yolu:


#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

Bir Site Koleksiyonundaki Tüm Belge Kitaplıklarını Listelemek için SharePoint Çevrimiçi PowerShell

Komut dosyasını yeniden kullanılabilir bir işleve saralım ve SharePoint Online site koleksiyonundan belge kitaplıklarını almak için bazı hata işleme ekleyelim.


#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

PnP PowerShell ile SharePoint Online'daki tüm belge kitaplıklarını listelemek için şunu kullanın: PnP PowerShell kullanarak SharePoint Online'daki Tüm Belge Kitaplıklarını Alın

İlgili makaleler