4

I can retrieve a title $list.Title, but a title is not the same as url.

In C# I can get list.DefaultViewUrl, which doesn't seem to be an option in Powershell.

I found this solution with $List.RootFolder.Url but it returns empty, so I assume it's not available for SharePoint Online.

Anything else I can try?

6

How to retrieve List Url in SharePoint Online using PowerShell

CSOM

Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
   $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}

$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password

$list = $context.Web.Lists.GetByTitle($listTitle)
$context.Load($list.RootFolder)
$context.ExecuteQuery()

$listUrl = $list.RootFolder.ServerRelativeUrl

REST

SharePoint RESTful web services could be consumed in PowerShell, follow an article Consuming the SharePoint 2013 REST API from PowerShell for a more details.

Endpoint: /_api/web/lists/getByTitle('<list title>')/RootFolder?$select=ServerRelativeUrl

Example:

$Url = $WebUrl + "/_api/web/lists/getByTitle('" + $listTitle +  "')/RootFolder?$select=ServerRelativeUrl"  
$data = Invoke-RestSPO $Url Get $UserName $Password
$listUrl = $data.ServerRelativeUrl

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.