SharePoint Online: Get sites with custom themes using PnP
Scenario
You want to make an inventory of what site themes (custom or default) have been applied by your users.
Unfortunately, there is no direct way to find whether a site is using a custom theme, other than going to a site and checking. The solution presented here describes a tenant-wide workaround which uses PnP Powershell.
Theme Gallery
There is a semi-hidden list called Theme Gallery that gets updated whenever a site theme is changed. You can find it under the following url:
https://TENANT.sharepoint.com/sites/YOURSITENAME/_catalogs/theme
or by navigating to classic Site Settings:
Whenever a theme is changed on a site a folder is created in the Theme Gallery, called Themed :
Inside the Themed folder you can find folders for each theme that was applied on the site at any point in time. The site may not be currently using any of those:
PnP Powershell
You can verify if the extra folders are present using PnP cmdlets:
$items = (Get-PnPListItem -List "Theme Gallery") | where {($_["FSObjType"] -eq 1) -and ($_["FileLeafRef"] -ne "15") }
if($items.Count -gt 0) {
# this site used at some point an alternative theme
}
Loop through your sites to find out which ones modified their theme:
$sites = Import-CSV YourCSVWIthSites.csv
foreach($site in $sites) {
Write-host $site.Url
$items = (Get-PnPListItem -List "Theme Gallery") | where {($_["FSObjType"] -eq 1) -and ($_["FileLeafRef"] -ne "15") }
if($items.Count -gt 0)
{
Out-File -FilePath C:\users\Public\Themedsites.txt -InputObject $site.Url -Append
}
}
See Also
https://swissredev.sharepoint.com/sites/MigrationSite_Arleta_147/\_catalogs/theme
https://swissredev.sharepoint.com/sites/MigrationSite_Arleta_147/\_catalogs/theme
https://swissredev.sharepoint.com/sites/MigrationSite_Arleta_147/\_catalogs/theme
https://swissredev.sharepoint.com/sites/MigrationSite_Arleta_147/\_catalogs/theme
PnP PowerShell overview
Customize your site header using PnP
Generate SharePoint theme using Theme Generator tool