Site Scripting creating new lists every time

Iron Contributor

The documentation says that running site scripts is nondestructive in that if a list already exists the script will skip creating a new one and update the existing list and I could have sworn it was doing that not long ago but in my testing now I am getting a brand new list every time I run my script. It is just appending a number to the end of the internal name and creating a new list. Did something change or is there something I'm doing wrong to cause that?

6 Replies
Has the display name of your list been changed since creation?

@Rob EllisNo, I'm working on adding columns and views so as I add them I rerun this script to update the script stored in the tenant. Maybe it makes a difference if I delete the site design and re-add it rather than just updating the script?

 

$adminSiteUrl = "https://tenant-admin.sharepoint.com"
$siteScriptId = "<guid>"
$siteScriptFile = $PSScriptRoot + "\ConfigurePMOSite.json"
$cred = Get-Credential
Connect-SPOService $adminSiteUrl -Credential $cred
Set-SPOSiteScript -Identity $siteScriptId -Content (Get-Content $siteScriptFile -Raw)
The process you are following is the correct one, as I understand it.

Having now made the change to the script - if you run it on a brand new site, then run it a 2nd time - do you get the issue?

(Just trying to confirm whether the issue is the multiple runs, or the script change)

@Rob EllisI figured out what is going on. I am using the site script to create a new list but I was trying to be a good "old school" SharePoint developer and create the list name without any spaces. So when I was using the "CreateSPList" verb I was using something like "ListName" as the value for listName in the script command and then I was setting the title to "List Name" with a space in it as a subaction.

 

But if you do that and re-run the script it tries to find a list with a display name of "ListName" and there isn't one. So it creates a new list called "ListName" and a display name of "List Name". Because there is already a list called "ListName" it adds a number to the end of it and recreates it.

 

Does that make sense? Bottom line, I need to be okay creating lists and libraries with spaces in the internal name (my inner SharePoint developer self is cringing at that comment).

aha! So when I originally asked 'Has the display name of your list been changed since creation?' - you actually meant yes, right? :)

@Rob Ellis<sheepish grin>