SharePoint Online: Change List or Library 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?

In SharePoint Online, when you create a list, the list’s URL is automatically generated. This URL can be used to link or share the list with others. However, you may need to change the URL for different reasons, such as renaming the list or using a different name for it. This article will show you how to change the URL of a SharePoint Online list using PowerShell.

Renaming a list title 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 the 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 other 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, let’s change the list URL in SharePoint Online with PowerShell.

SharePoint Online: Change List URL using PowerShell

How to change the URL of a document library in SharePoint Online? Well, Let’s 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)
 
    #sharepoint online change library url powershell   
    $List.Rootfolder.MoveTo($NewListURL)
    $Ctx.ExecuteQuery()

    #Keep the List name as is
    $List.Title=$ListName 
    $List.Update()
    $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 list or document library! We also change the list URL in SharePoint Online with PnP PowerShell with a few lines of script.

Rename Document Library URL using PnP PowerShell

Let’s use PnP PowerShell to change the document library URL in SharePoint Online.

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/p/"
$ListName = "Shared Documents"
$NewListURL = "documents"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the List
$List= Get-PnPList -Identity $ListName -Includes RootFolder

#sharepoint online powershell change list url
$List.Rootfolder.MoveTo($NewListURL)
Invoke-PnPQuery

If you want to change just the list title instead of the list URL, refer: SharePoint Online: How to Rename a List using PowerShell?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

16 thoughts on “SharePoint Online: Change List or Library URL using PowerShell

  • Hello,
    Does the PowerShell script work for MFA enabled admins as well ?

    Reply
    • Yes! Use the PnP PowerShell script with: Connect-PnPOnline -Url $SiteURL -Interactive

      Reply
  • There is a side effect! List/Library can’t be restored once the url is changed.

    Reply
  • ok..Thanks I will give try and let you know…Thanks a lot.

    Reply
  • Thanks for quick reply.I am having list with around 1 million records so not able to move it. Any solution on it.

    Reply
    • Delete the Items to recycle bin and then restore them back after the URL change is another alternative solution!

      Reply
  • Thank you for this! It’s very useful. I do have a question though. I’ve been getting the following threshold error with a few large lists –

    Invoke-PnPQuery : The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.

    I’ve seen some of your workarounds in other posts, but I’m not sure if any of them could be applied in this case. Any suggestions you have would be greatly appreciated.

    Reply
    • did you get any solution?

      Reply
      • For Larger lists and Libraries – The only workaround so far is: Moving Files outside the library, Perform the URL Change and then move back the files.

        Reply
  • hello, I keep getting the following error: “Method invocation failed because [Microsoft.SharePoint.Client.Folder] does not contain a method named ‘MoveTo’.”

    Any ideas why?

    Reply
    • “MoveTo” is a new addition in CSOM. Please update your CSOM assemblies/module.

      Reply
    • Hi Salaudeen,

      I have updated the CSOM assemblies to the latest version. Still I am getting the above mentioned error.
      “Error changing List URL! Method invocation failed because [Microsoft.SharePoint.Client.Folder] does not contain a method named ‘MoveTo’.”

      What needs to be done here.

      Reply
  • This command needs to be ran directly on the server? I’m using Office 365 SharePoint (not on-prem) and I’m having a hard time changing the URL of a list. The “open with explorer” no longer is available apparently in this new style.

    Reply
    • Its PowerShell for SharePoint Online and can be installed from any client machine where SharePoint Client SDK or SharePoint Online PowerShell module is installed. “Open with Explorer” is moved under “Views” drop-down!

      Reply
  • Man, you saved me hours of work! I had migrated a 50+ GB and 95.000 documents document library with a fixed URL (had removed blank spaces), but the original one was needed.
    Your script ended after timing out, but the doclib’s URL was successfully changed.
    Thank you very much.

    Reply

Leave a Reply