From 72f56ff7563ab24260b4c5441a25bede260ccb6a Mon Sep 17 00:00:00 2001 From: ojopiyo <122151392+ojopiyo@users.noreply.github.com> Date: Thu, 11 Dec 2025 20:29:10 +0000 Subject: [PATCH 1/2] Update README.md Improvements / Safety Features 1. Error Handling - The try/catch block ensures the script reports errors instead of failing silently. 2. Check for Existing URL - Prevents overwriting a folder or list that already exists at the target URL. 3. Updates List Object Directly - Set-PnPList -Identity $list avoids confusion after moving the folder. 4. Informative Output - Write-Host shows clear messages on success or failure. --- scripts/spo-change-list-url/README.md | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/spo-change-list-url/README.md b/scripts/spo-change-list-url/README.md index 2ad231b8b..faaff4d5d 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 +} ``` From fbcb244049dcb6fb640e8afb0ea9175d84179601 Mon Sep 17 00:00:00 2001 From: Paul Bullock Date: Thu, 18 Dec 2025 08:10:49 +0000 Subject: [PATCH 2/2] Added metadata and affirmation updates --- scripts/spo-change-list-url/README.md | 1 + scripts/spo-change-list-url/assets/sample.json | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/spo-change-list-url/README.md b/scripts/spo-change-list-url/README.md index faaff4d5d..bb89d0dbd 100644 --- a/scripts/spo-change-list-url/README.md +++ b/scripts/spo-change-list-url/README.md @@ -64,6 +64,7 @@ try { | 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": "",