PowerShell Script: Change Site Theme

Scenario:

We have customized a site theme as explained in previous post. Now, we need to apply it on Site and all its webs.

Resolution:

$name = [Name of theme]

$filepath = [Path of the theme]

$bytes = [System.IO.File]::ReadAllBytes($filepath + “\” $name);

$site = Get-SPSite(“url of site collection”)

$rootWeb $site.RootWeb

$list $rootWeb.Lists[“Theme Gallery”]

$list.RootFolder.Files.Add($name,$bytes)

$theme = [Microsoft.SharePoint.Utilities.ThmxTheme]::Open

($site,“_catalogs/theme/”$name)


foreach($web in $site.AllWebs)

{

$theme.ApplyTo($web,$false)

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: