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?

In SharePoint Online, 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.

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 the “List” query parameter is the ID of the list. Just replace %2D with “-” and you’ll get the GUID of the list.

get all sharepoint library ids powershell sharepoint online

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

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.

SharePoint Online PowerShell to Get List ID

If you want to get a list by its GUID, use: How to Get a List from GUID in SharePoint Online?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “SharePoint Online: PowerShell to Get List ID (GUID)

  • 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?

    Reply
    • List objects are scoped at web level. So, You may have to iterate through each web in the tenant and fetch lists.

      Reply

Leave a Reply

Your email address will not be published.