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:
PnP PowerShell to Get List GUID
Here is how to get SharePoint online list GUID.
PowerShell to Get GUID of All Lists in SharePoint Online:
How about getting the ID of all lists and libraries in a site?
If you want to get a list by its GUID, use: How to Get a List from GUID in SharePoint Online?
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 }
PnP PowerShell to Get List GUID
Here is how to get SharePoint online list GUID.
#Config Parameters $SiteURL="https://crescent.sharepoint.com" $ListTitle = "Shared Documents" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get list by GUID $List = Get-PnPList -Identity $ListTitle #Get List GUID Write-host "List ID:" $List.Id
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.
If you want to get a list by its GUID, use: How to Get a List from GUID in SharePoint Online?
No comments:
Please Login and comment to get your questions answered!