SharePoint Online: Get a Document Library using PowerShell

Requirement: Get a Document Library in SharePoint Online using PowerShell

SharePoint Online: Get a Document Library using PowerShell
Here is the PowerShell to Get SharePoint Online document library
#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"

#Variables
$SiteURL = "https://crescent.sharepoint.com/Sites/Marketing"
$DocLibraryName="Project Documents"

#Setup Credentials to connect
$Cred = Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
    #sharepoint online get document library powershell
    $DocLibrary = $Ctx.Web.Lists.GetByTitle($DocLibraryName)
    $Ctx.Load($DocLibrary)
    $Ctx.ExecuteQuery()

    Write-host "Total Number of Items in the Document Library:"$DocLibrary.ItemCount
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
This script gets the document library and returns a number of items from the library. To get all document libraries in SharePoint Online, use: SharePoint Online: PowerShell to Get Document Libraries
SharePoint Online: Get a Document Library using PowerShell SharePoint Online: Get a Document Library using PowerShell Reviewed by Salaudeen Rajack on August 25, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.