Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions scripts/spo-change-list-url/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,29 @@ $newListName = "Logo Universe"
# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Get the SharePoint list
$list = Get-PnPList -Identity $oldListName

# Move SharePoint list to the new URL
$list.Rootfolder.MoveTo($newListUrl)
Invoke-PnPQuery

# Rename List
Set-PnPList -Identity $oldListName -Title $newListName
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
}

```

Expand Down