SharePoint Online: PowerShell to Find List ID (GUID)
Requirement: Get List ID in SharePoint Online using PowerShell.
How to Get the List ID in SharePoint Online?
In SharePoint Online, each list has a unique identifier called a GUID (Globally Unique Identifier), which is used to distinguish it from other lists within the same site. You can get the list ID in a couple of ways. You can either use the web browser or PowerShell. This article will show you how to get the ID for any SharePoint Online list or library.
- Browse to your List >> Click on Settings >> List Settings.
- The list settings URL looks like https://crescent.sharepoint.com/_layouts/15/listedit.aspx?List={d50ffc71%2D8b0f%2D4cbe%2Da1db%2D5667fee88468}, Here what you see for the “List” query parameter is the ID of the list. Just replace %2D with “-” and you’ll get the GUID of the list.
Alright, let’s take a look at how you can use PowerShell to get the ID of a list in SharePoint Online. This will help you work with or manage your lists using PowerShell scripts.
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 the SharePoint Online list or document library GUID using PnP PowerShell:
#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
Get all SharePoint Document Library IDs using PowerShell in SharePoint Online
Similarly, You can get the Ids of all document libraries with:
Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary"}
PowerShell to Get GUID of All Lists in SharePoint Online:
How about getting the ID of all lists and libraries on a site? Here is the PowerShell script to list all the SharePoint library ids in a site collection.
#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 their GUIDs from a given SharePoint Online site.
In summary, finding the SharePoint Online list GUID is a simple process that can be accomplished through the SharePoint Online user interface or PowerShell, as explained in this article. If you want to get a list by its GUID, use: How to Get a List from GUID in SharePoint Online?
Can this script be modified so that if we have the List GUID, it can provide us the name and location of where it’s located in the tenant?
List objects are scoped at web level. So, You may have to iterate through each web in the tenant and fetch lists.