0

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.

3 Answers 3

1

Convert string to guide before passing it getlistbyid

$guid = [GUID] ("guidnumber") $listname=$web.Lists.GetById($guid) 
1

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 } 

enter image description here

0

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 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.