GitHub Icon Image
GitHub

Delete custom color themes from SharePoint

Summary

Have you been creating a lot of beautiful themes lately and testing them in your dev tenant, but don't want to keep them anymore? If yes, then this PowerShell script is for you.

  • PnP PowerShell
  • SPO Management Shell
  • CLI for Microsoft 365

# SharePoint online admin center URL
$SPOAdmminSite = "https://contoso-admin.sharepoint.com"

$themesToKeep = "Contoso Explorers", "Multicolored theme"

# Connect to SharePoint online admin center
Connect-PnPOnline -Url $SPOAdmminSite -Interactive

# Get all themes from the current tenant
$themes = Get-PnPTenantTheme

$themes = $themes | where {-not ($themesToKeep -contains $_.name)}
$themes | Format-Table name

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

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

foreach ($theme in $themes)
{
  $progress++
  write-host $progress / $total":" $theme.name
  
  # Delete custom color themes from SharePoint
  Remove-PnPTenantTheme -Identity "$($theme.name)"
}

# Disconnect SharePoint online connection
Disconnect-PnPOnline

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

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?


# SharePoint online admin center URL
$SPOAdmminSite = "https://contoso-admin.sharepoint.com"

$themesToKeep = "Contoso Explorers", "Multicolored theme"

# Connect to SharePoint online admin center
Connect-SPOService -Url $SPOAdmminSite

# Get all themes from the current tenant
$themes = Get-SPOTheme

$themes = $themes | where {-not ($themesToKeep -contains $_.name)}
$themes | Format-Table name

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

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

foreach ($theme in $themes)
{
  $progress++
  write-host $progress / $total":" $theme.name
  
  # Delete custom color themes from SharePoint
  Remove-SPOTheme -Identity "$($theme.name)"
}

# Disconnect SharePoint online connection
Disconnect-SPOService

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


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

$themesToKeep = "Contoso Explorers", "Multicolored theme"

# Get all themes from the current tenant
$themes = m365 spo theme list | ConvertFrom-Json

$themes = $themes | where {-not ($themesToKeep -contains $_.name)}
$themes | Format-Table name

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

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

foreach ($theme in $themes)
{
  $progress++
  write-host $progress / $total":" $theme.name
  
  # Delete custom color themes from SharePoint
  m365 spo theme remove --name "$($theme.name)" --confirm
}

# Disconnect SharePoint online connection
m365 logout

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

Important changes coming to the way you login into CLI for Microsoft 365 (effective 9th September 2024) see Changes in PnP Management Shell registration in Microsoft 365

Contributors

Author(s)
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