GitHub Icon Image
GitHub

Change SharePoint Online List URL

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

  • PnP 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
}

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?

Contributors

Author(s)
Ganesh Sanap
ojopiyo

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.

Back to top Script Samples
Generated by DocFX with Material UI