How to Get a List from GUID in SharePoint Online?

Requirement: Get a List from GUID in SharePoint Online.

Get List by GUID in SharePoint Online:
To get a list from its GUID, you can use this URL: https://crescent.sharepoint.com/_layouts/15/listedit.aspx?List=GUID ,
sharepoint online get list from GUID
This takes you to the list settings page of the given GUID. Let's use PowerShell CSOM to get a list from GUID:

PowerShell to Get List from GUID 
Here is how to get SharePoint Online list by its GUID
#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"
$ListGUID = [System.Guid]("9a939664-ace4-44af-ad6e-26cefd2e8d32")

#Get Credentials to connect
$Cred= Get-Credential

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
#Get List by id
$List=$Ctx.Web.Lists.GetById($ListGUID)
$Ctx.load($List)
$Ctx.ExecuteQuery()

Write-host "Total Number of List Items:"$List.ItemCount

PnP PowerShell to Get List by GUID in SharePoint Online
#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListGUID = [System.Guid]("c94f7b39-2e07-4e40-90b7-c613630e5f8d")

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get list by GUID
$List = Get-PnPList -Identity $ListGUID

#Get List Name
Write-host "List Name:" $List.Title

If you want to get list guid in SharePoint Online: How to Get List GUID in SharePoint Online?
How to Get a List from GUID in SharePoint Online? How to Get a List from GUID in SharePoint Online? Reviewed by Salaudeen Rajack on February 22, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.