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.
Copied
# 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
Copied
# 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
Copied
# 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
Contributors
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.