0

Getting error while applying theme to site collection and all subsite underneath Issue using Powershell in SharePoint 2013

Below is the code

$themeName = "PaletteTheme"
$SPSite = Get-SPSite "http://SP2013" 
$i=0;
$r =  $SPSite.Url + "/_catalogs/theme/15/PaletteThemeVal.spcolor"


foreach ($SPWeb in $SPSite.AllWebs) 
{       
        Write-Host "SP--Web" + $SPWeb.Url
    $colorfile = $SPWeb.GetFile($r)
    Write-Host $colorfile
        $theme=[Microsoft.SharePoint.Utilities.SPTheme]::Open($themeName, $colorfile);
        Write-Host $theme
        Write-Host $theme.Name "to" $SPWeb.Title;         
        $theme.ApplyTo($SPWeb, $false);
}

The theme is getting appied to the root site collection but not to the subsites under neath it. Below is the error i am gettingenter image description here

1

In the below line of code, you are trying to fetch the colorfile from the sub web but it's not in the sub web; it's in the root web, that's why it works fine in the root web, but fails in other webs.

 $colorfile = $SPWeb.GetFile($r)

Try using the below code and logic,

Add-PSSnapin Microsoft.SharePoint.PowerShell

$themeName = "PaletteTheme"
$SPSite = Get-SPSite "http://SP2013" 
$r =  $SPSite.Url + "/_catalogs/theme/15/palette005.spcolor"
$rootwebFile = $SPSite.rootweb.GetFile($r)

foreach ($SPWeb in $SPSite.AllWebs) 
{       
    Write-Host "SP--Web" + $SPWeb.Url
    Write-Host $colorfile
    $theme=[Microsoft.SharePoint.Utilities.SPTheme]::Open($themeName, $rootwebFile);
    Write-Host $theme
    Write-Host $theme.Name "to" $SPWeb.Title;         
    $theme.ApplyTo($SPWeb, $false);
}

Remove-PSSnapin Microsoft.SharePoint.PowerShell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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