I've found that import-spweb duplicates items in the theme gallery. Using export-spweb and then import-spweb, the target site is doubled up on each of the themes in the theme gallery. Everytime I do another import-spweb on this site collection, even after deleting the site collection and creating a blank one with no template, it adds another copy of each theme to the theme gallery.

So I'd like to write a little PowerShell script that will find duplicates and delete them, but I'm not sure what files I should be deleting. I looked in the "Theme Gallery" list on the SPWeb I've created, but it's items are the actual theme files.

get-spsite | %{
    $_.allwebs | %{
        $theme_gallery = $_.lists|?{$_.title -eq "Theme Gallery"}
        $theme_gallery.items|select name


big list of files

How can a Theme be removed from the gallery for a site with PowerShell?

1 Answer 1


The below code will delete the mentioned theme from the web. You can modify it to loop through to find the duplicates and delete theme.

$site=Get-SPSite "http://servername/sites/sitename"
if ($web.GetFile("_catalogs/theme/YourCustomTheme.thmx").Exists -eq $true)
   $file = $web.GetFile("_catalogs/theme/YourCustomTheme.thmx")
   write-host -f yellow "File is not in the Theme Gallery"


To find the exact name and path of the theme, follow below steps,

  1. Open SharePoint Designer -> open site.
  2. Click All files -> _catalogs -> theme -> This will list all the installed themes.

Hope this will help you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.