Tuesday, April 1, 2014

Apply SharePoint 2013 Theme to SiteCollection and its sub site using PowerShell Script

//Add the snapin for the power shell
Add-PSSnapin "microsoft.sharepoint.powershell"

//Set the site collection URL where the theme has to be applied
$url = "Site Collection URL"
$web = Get-SPWeb $URL

//Select the pallet color file,  if you do not have create one from this link.
$file = $web.GetFile($web.ServerRelativeUrl + "/_catalogs/theme/15/MyTheme01.spcolor")

$theme = [Microsoft.SharePoint.Utilities.SPTheme]::Open("MyTheme", $file)
$site = Get-SPSite -Identity $url
Write-Host "RootWeb Theme: " + $site.RootWeb.ThemedCssFolderUrl
foreach ($web in $site.AllWebs) {
Write-Host "Web Title: " $web.Title
  Write-Host "Web Theme CSS: " $web.ThemeCssUrl
Write-Host "Web Theme: " $web.ThemedCssFolderUrl
$web.ThemedCssFolderUrl = $site.RootWeb.ThemedCssFolderUrl
Write-Host "Web Theme: " $web.ThemedCssFolderUrl

PS: The above code is tested in my development server and it runs perfect for SharePoint 2013 and its the risk of the users to run the code in their environment. So run at your own risk! :)

Happy Browsing!

No comments:

Post a Comment