How to get list name using its guid in CSOM powershell
I tried:
$listname=$web.Lists.GetById("guid") But this is not working. Please suggest.
Convert string to guide before passing it getlistbyid
$guid = [GUID] ("guidnumber") $listname=$web.Lists.GetById($guid) You need to make sure there are not special chars in GUID.
An example for you:
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" $siteURL = "https://xxx.sharepoint.com/sites/xx" $userId = "[email protected]" $pwd = Read-Host -Prompt "Enter password" -AsSecureString $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd) $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) $ctx.credentials = $creds try{ $lists = $ctx.web.Lists #$list = $lists.GetByTitle("list666") $guid = [GUID] ("8A3AE548-0F20-4705-A047-5CF855543704") $list = $lists.GetById($guid) $ctx.load($list) $ctx.executeQuery() $list.Title } catch{ write-host "$($_.Exception.Message)" -foregroundcolor red } This code works in Powershell:
Add-PSSnapin "Microsoft.SharePoint.PowerShell" $spWeb = Get-SPWeb "https://your.sharepoint.url/any-site/" # If the GUID is a string, set a GUID Powershell object: $spListGUID = [GUID]"{ABCD1234-AB12-AB12-AB12-ABCDEF123456}" #Get the list via its GUID: $spList = $spWeb.Lists[$spListGUID] Write-Host "List Title: " $spList.Title