Skip to content

Commit 935b752

Browse files
authored
Merge pull request #891 from ojopiyo/patch-1
Update README.md
2 parents 73fda0c + fbcb244 commit 935b752

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

scripts/spo-change-list-url/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,29 @@ $newListName = "Logo Universe"
2929
# Connect to SharePoint online site
3030
Connect-PnPOnline -Url $siteUrl -Interactive
3131
32-
# Get the SharePoint list
33-
$list = Get-PnPList -Identity $oldListName
34-
35-
# Move SharePoint list to the new URL
36-
$list.Rootfolder.MoveTo($newListUrl)
37-
Invoke-PnPQuery
38-
39-
# Rename List
40-
Set-PnPList -Identity $oldListName -Title $newListName
32+
try {
33+
# Get the list object
34+
$list = Get-PnPList -Identity $oldListName -ErrorAction Stop
35+
36+
# Check if the target URL already exists
37+
$existingFolder = Get-PnPFolder -Url $newListUrl -ErrorAction SilentlyContinue
38+
if ($existingFolder) {
39+
Write-Host "Error: A list or folder already exists at '$newListUrl'. Aborting." -ForegroundColor Red
40+
return
41+
}
42+
43+
# Move the list's root folder to the new URL
44+
$list.RootFolder.MoveTo($newListUrl)
45+
Invoke-PnPQuery
46+
Write-Host "List URL successfully changed to '$newListUrl'." -ForegroundColor Green
47+
48+
# Rename the list display name
49+
Set-PnPList -Identity $list -Title $newListName
50+
Write-Host "List display name successfully changed to '$newListName'." -ForegroundColor Green
51+
52+
} catch {
53+
Write-Host "An error occurred: $_" -ForegroundColor Red
54+
}
4155
4256
```
4357

@@ -50,6 +64,7 @@ Set-PnPList -Identity $oldListName -Title $newListName
5064
| Author(s) |
5165
|-----------|
5266
| [Ganesh Sanap](https://ganeshsanapblogs.wordpress.com/about) |
67+
| ojopiyo |
5368

5469
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
5570
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-change-list-url" aria-hidden="true" />

scripts/spo-change-list-url/assets/sample.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"shortDescription": "This sample script shows how to change SharePoint online list URL and rename the list after list creation using PnP PowerShell",
77
"url": "https://pnp.github.io/script-samples/spo-change-list-url/README.html",
88
"longDescription": [],
9-
"creationDateTime": "2023-03-22",
10-
"updateDateTime": "2023-03-22",
9+
"creationDateTime": "2025-12-11",
10+
"updateDateTime": "2025-12-11",
1111
"products": [
1212
"SharePoint"
1313
],
@@ -35,6 +35,12 @@
3535
}
3636
],
3737
"authors": [
38+
{
39+
"gitHubAccount":"ojopiyo",
40+
"company": "",
41+
"pictureUrl": "https://avatars.githubusercontent.com/u/122151392?v=4",
42+
"name": "ojopiyo"
43+
},
3844
{
3945
"gitHubAccount": "ganesh-sanap",
4046
"company": "",

0 commit comments

Comments
 (0)