GitHub Icon Image
GitHub

Delete custom SharePoint site designs

Summary

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!

Warning

Please be aware this script contains a command that will remove or delete an artifact, ensure you test and understand the implications of running the script.

  • SPO Management Shell
  • PnP PowerShell
  • CLI for Microsoft 365
Connect-SPOService "https://contoso-admin.sharepoint.com"

$keepThese = "Register the new site", "Corporate Basic Site", "Corporate Internal Site"
$siteDesigns = Get-SPOSiteDesign
$siteDesigns = $siteDesigns | Where-Object { -not ($keepThese -contains $_.Title)}

if ($siteDesigns.Count -eq 0) { break }

$siteDesigns | Format-Table Title, SiteScriptIds, Description
Read-Host -Prompt "Press Enter to start deleting (CTRL + C to exit)"
$progress = 0
$total = $siteDesigns.Count

foreach ($siteDesign in $siteDesigns)
{
  $progress++
  Write-Host $progress / $total":" $siteDesign.Title
  Remove-SPOSiteDesign $siteDesign.Id
}

Check out the SPO Management Shell to learn more at: Introduction SharePoint Online Management Shell | Microsoft Docs


$tenantAdminUrl = "https://contoso-admin.sharepoint.com"

Connect-PnPOnline -Url $tenantAdminUrl -Interactive

$SiteDesignTitlesToKeep = "Cat Lovers United", "Multicolored theme"
$sitedesigns = Get-PnPSiteDesign
$sitedesigns = $sitedesigns | where {-not ($sparksjoy -contains $_.Title)}
$sitedesigns | Format-Table Title, SiteScriptIds, Description
if ($sitedesigns.Count -eq 0) { break }
Read-Host -Prompt "Press Enter to start deleting (CTRL + C to exit)"
$progress = 0
$total = $sitedesigns.Count
foreach ($sitedesign in $sitedesigns)
{
  $progress++
  write-host $progress / $total":" $sitedesign.Title
  Remove-PnPSiteDesign -Identity $sitedesign.Id -Force:$true
}

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell


# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
   m365 login
}

$keepThese = "Register the new site", "Corporate Basic Site", "Corporate Internal Site"

# Get all site designs from the current tenant
$siteDesigns = m365 spo sitedesign list | ConvertFrom-Json

$siteDesigns = $siteDesigns | Where-Object { -not ($keepThese -contains $_.Title)}

if ($siteDesigns.Count -eq 0) { break }

$siteDesigns | Format-Table Title, SiteScriptIds, Description

Read-Host -Prompt "Press Enter to start deleting (CTRL + C to exit)"
$progress = 0
$total = $siteDesigns.Count

foreach ($siteDesign in $siteDesigns)
{
  $progress++
  Write-Host $progress / $total":" $siteDesign.Title
  m365 spo sitedesign remove --id $siteDesign.Id
}

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Contributors

Author(s)
Paul Bullock
Leon Armston
Ganesh Sanap

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI