Skip to main content

Delete custom SharePoint site scripts

Author: Laura Kokkarinen

Site designs and especially site scripts can be something that ends up just hanging around in your tenant for a long time even though you no longer need them for anything. Use the scripts below to get rid of them. You might also find some site scripts that are not linked to any site design and hence never get executed!

$sparksjoy = "Project Site", "Issues List"
$siteScripts = m365 spo sitescript list -o json | ConvertFrom-Json
$siteScripts = $siteScripts | where { -not ($sparksjoy -contains $_.Title)}
if ($siteScripts.Count -eq 0) { break }
$siteScripts | Format-Table Title, SiteScriptIds, Description
Read-Host -Prompt "Press Enter to start deleting (CTRL + C to exit)"
$progress = 0
$total = $siteScripts.Count
foreach ($siteScript in $siteScripts)
{
$progress++
Write-Host $progress / $total":" $siteScript.Title
m365 spo sitescript remove -i $siteScript.Id --force
}
CTRL + M