SharePoint Online: PowerShell to Get List URL

Requirement: PowerShell to Get SharePoint Online List URL

SharePoint Online PowerShell to Get List URL
Here is how to get list URL in SharePoint Online with PowerShell:
#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"

#Variables for Processing
$SiteURL = "https://crescenttech.sharepoint.com/sites/marketing"
$ListName = "Documents"

#Get Credentials to connect
$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the Web and List Objects
$Web = $Ctx.Web
$Ctx.Load($Web)
$List = $Web.Lists.GetByTitle($ListName)
$Ctx.Load($List.RootFolder)
$Ctx.ExecuteQuery()

#List Relative URL
Write-host "List Relative URL:"$List.RootFolder.ServerRelativeUrl

#Get List Full URL
If($Ctx.Web.ServerRelativeUrl -eq "/")
{
    $ListURL = $("{0}{1}" -f $Ctx.Web.Url, $List.RootFolder.ServerRelativeUrl)
}
Else
{
    $ListURL = $("{0}{1}" -f $Ctx.Web.Url.Replace($Ctx.Web.ServerRelativeUrl,''), $List.RootFolder.ServerRelativeUrl)
}
Write-host "List Full URL:"$ListURL
SharePoint Online: PowerShell to Get List URL SharePoint Online: PowerShell to Get List URL Reviewed by Salaudeen Rajack on May 29, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.