SharePoint Online: PowerShell to Get List ID (GUID)

Requirement: Get List ID in SharePoint Online using PowerShell

How to Get the List ID in SharePoint Online?
If you go to List Settings of any list or library, the URL looks like: https://crescent.sharepoint.com/_layouts/15/listedit.aspx?List=d50ffc71%2D8b0f%2D4cbe%2Da1db%2D5667fee88468, Here what you see for "List" query parameter is the ID of the list. Just replace %2D with "-" and you'll get the GUID of the list.

SharePoint Online: PowerShell to Get List ID
Let's get the ID of a List using 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"
$ListName = "Contacts"

#Get 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)
    
    #Get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.ExecuteQuery()

    #Get List GUID
    Write-host -f Green $List.Id
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

PowerShell to Get GUID of All Lists in SharePoint Online: 
How about getting the ID of all lists and libraries in a site?
#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"

#Get 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)
    
    #Get All Lists
    $Lists = $Ctx.Web.Lists
    $Ctx.Load($Lists)
    $Ctx.ExecuteQuery()

    #Get List Title and ID
    $Lists | Select Title, ID
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
This PowerShell script retrieves all lists and its GUIDs from a given SharePoint Online site.
SharePoint Online PowerShell to Get List ID
SharePoint Online: PowerShell to Get List ID (GUID) SharePoint Online: PowerShell to Get List ID (GUID) Reviewed by Salaudeen Rajack on August 12, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.