Configure

Change SharePoint Online List URL

This sample script shows how to change SharePoint online list URL and rename the list after list creation using PnP PowerShell

Summary

This sample script shows how to change SharePoint online list URL and rename the list after list creation using PnP PowerShell.

Scenario inspired from this blog post: Change SharePoint Online List URL using PnP PowerShell

Outupt Screenshot

powershell

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Current display name of SharePoint list
$oldListName = "Images List"

# New list URL
$newListUrl = "Lists/LogoUniverse"

# New display name for SharePoint list
$newListName = "Logo Universe"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

try {
    # Get the list object
    $list = Get-PnPList -Identity $oldListName -ErrorAction Stop

    # Check if the target URL already exists
    $existingFolder = Get-PnPFolder -Url $newListUrl -ErrorAction SilentlyContinue
    if ($existingFolder) {
        Write-Host "Error: A list or folder already exists at '$newListUrl'. Aborting." -ForegroundColor Red
        return
    }

    # Move the list's root folder to the new URL
    $list.RootFolder.MoveTo($newListUrl)
    Invoke-PnPQuery
    Write-Host "List URL successfully changed to '$newListUrl'." -ForegroundColor Green

    # Rename the list display name
    Set-PnPList -Identity $list -Title $newListName
    Write-Host "List display name successfully changed to '$newListName'." -ForegroundColor Green

} catch {
    Write-Host "An error occurred: $_" -ForegroundColor Red
}

Contributors

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Tool documentation & references

Keep exploring