diff --git a/scripts/spo-change-list-url/README.md b/scripts/spo-change-list-url/README.md index 2ad231b8b..bb89d0dbd 100644 --- a/scripts/spo-change-list-url/README.md +++ b/scripts/spo-change-list-url/README.md @@ -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 +} ``` @@ -50,6 +64,7 @@ Set-PnPList -Identity $oldListName -Title $newListName | Author(s) | |-----------| | [Ganesh Sanap](https://ganeshsanapblogs.wordpress.com/about) | +| ojopiyo | [!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] diff --git a/scripts/spo-change-list-url/assets/sample.json b/scripts/spo-change-list-url/assets/sample.json index a874aff0f..3ca5836f0 100644 --- a/scripts/spo-change-list-url/assets/sample.json +++ b/scripts/spo-change-list-url/assets/sample.json @@ -6,8 +6,8 @@ "shortDescription": "This sample script shows how to change SharePoint online list URL and rename the list after list creation using PnP PowerShell", "url": "https://pnp.github.io/script-samples/spo-change-list-url/README.html", "longDescription": [], - "creationDateTime": "2023-03-22", - "updateDateTime": "2023-03-22", + "creationDateTime": "2025-12-11", + "updateDateTime": "2025-12-11", "products": [ "SharePoint" ], @@ -35,6 +35,12 @@ } ], "authors": [ + { + "gitHubAccount":"ojopiyo", + "company": "", + "pictureUrl": "https://avatars.githubusercontent.com/u/122151392?v=4", + "name": "ojopiyo" + }, { "gitHubAccount": "ganesh-sanap", "company": "",