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.

1

Convert string to guide before passing it getlistbyid

$guid = [GUID] ("guidnumber")
$listname=$web.Lists.GetById($guid)
| improve this answer | |
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 = "xxx@xxx.onmicrosoft.com"  
$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

| improve this answer | |
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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.