kwizcom banner advertisement

SharePoint Online: Change List URL using PowerShell

Requirement: Change URL of a List or Document Library in SharePoint Online using PowerShell.

How to Change the List URL in SharePoint Online?
Renaming a list doesn't change its URL! However, To change the URL of a List or Library in SharePoint Online we can use: File Explorer View, SharePoint Designer or PowerShell! To change the URL of a document library using Explore view:
  • Open the Document Library in "File Explore View"
  • Navigate One Level Up in the Explorer >> Select the Document Library to Rename 
  • Press "F2" (or Right Click and choose "Rename") >> Enter the new Name for your document library >> Hit "Enter"
    SharePoint Online Change List URL using PowerShell

Using Explore View and SharePoint Designer to change the URL of a SharePoint list is explained in my another post for SharePoint On-Premises is applicable for SharePoint Online as well: How to Change URL of a List or Document Library in SharePoint?. So Here, lets change list URL in SharePoint Online with PowerShell.

SharePoint Online: Change List URL using PowerShell
Lets change the URL of a SharePoint Online document library from "Project%20Documentation" to "ProjectDocs" using 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"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$ListName="Project Documentation"
$NewListURL="ProjectDocs"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the List
    $List=$Ctx.web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)

    #Change the URL of the List    
    $List.Rootfolder.MoveTo($NewListURL)
    $List.Title=$ListName #Keep the List name as is
    $Ctx.ExecuteQuery()

    Write-host -f Green "List URL has been changed!"
}
Catch {
    write-host -f Red "Error changing List URL!" $_.Exception.Message
}

This changes the URL of the given document library!
SharePoint Online: Change List URL using PowerShell SharePoint Online: Change List URL using PowerShell Reviewed by Salaudeen Rajack on September 29, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.