If you are a SharePoint administrator looking to quickly apply some basic branding to a site-collection in your SharePoint 2013 environment then you've come to the right spot.
Before we begin I assume you have a basic understanding of what Composed Looks are, and perhaps you spent some time playing around with this concept in SharePoint 2013.
If not, then don't worry. Here is a basic primer:
- Composed Look is basically a package which contains elements used for controlling the overall look and feel of a SharePoint site. This includes but not limited to Colors, Fonts, Background Image, CSS files, and Master Page files.
- Once created, Composed Look can be packaged by using the Design Manager feature, or we can use PowerShell to apply it across one or multiple site collections.
NOTE: In this post we will be focusing on creating a composed look from an .spcolor file then using PowerShell to apply the design to a site-site collection of our choice. We will not be demonstrating steps on how to apply design using Design Manager.
Step 1: Create a Composed Look (.spcolor file)
There are a couple of different ways we can approach this, but to make everyone's life a whole lot easier I recommend that you download and install a free SharePoint Color Palette Tool from Microsoft. Trust me, it will save you a ton of time.
- Open the SharePoint Color Palette Tool.
- Use the Color Slots pane to specify hex values for each color bucket. You can also expand each color bucket to further customize the colors. To better understand what page element each color bucket represents please refer to the following article: Color palettes and fonts in SharePoint 2013
- Changes made in the Color Slots pane will automatically appear in the Preview pane.
- When finished, save the .spcolor file to a desired location. I named my file customPalette.spcolor.
Step 2: Apply Color Palette using PowerShell
From this point forward we can relay on a simple PowerShell script to do the rest of the work for us. Keep in mind that the following script will apply changes to all SPWeb objects (sub-sites) within the designated site collections.
$siteCollectionUrl = $args[0]
$spSite = Get-SPSite $siteCollectionUrl
$spWeb = $spSite.RootWeb
$spFolder = $spWeb.GetFolder("_catalogs/theme/15")
$spFileCollection = $spFolder.Files
$file = Get-ChildItem "customPalette.spcolor"
$themeUrl = "_catalogs/theme/15/customPalette.spcolor"
$spFile = $spFileCollection.Add($themeUrl,$file.OpenRead(),$true)
$theme = [Microsoft.SharePoint.Utilities.SPTheme]::Open("Current", $spFile)
$spSite.AllWebs | % { Write-Host $_.Url; $theme.ApplyTo($_, $true);}
Make sure to save the above code as a .ps1 file. I named my file applydesign.ps1 and saved it to the same location as customPalette.spcolor file.
Now that we have a Color Palette (.spcolor) file from Step 1 and our PS script we are ready to execute:
$siteCollectionUrl = $args[0]
$spSite = Get-SPSite $siteCollectionUrl
$spWeb = $spSite.RootWeb
$spFolder = $spWeb.GetFolder("_catalogs/theme/15")
$spFileCollection = $spFolder.Files
$file = Get-ChildItem "customPalette.spcolor"
$themeUrl = "_catalogs/theme/15/customPalette.spcolor"
$spFile = $spFileCollection.Add($themeUrl,$file.OpenRead(),$true)
$theme = [Microsoft.SharePoint.Utilities.SPTheme]::Open("Current", $spFile)
$spSite.AllWebs | % { Write-Host $_.Url; $theme.ApplyTo($_, $true);}
Make sure to save the above code as a .ps1 file. I named my file applydesign.ps1 and saved it to the same location as customPalette.spcolor file.
- Open SharePoint 2013 Management Shell on one of the SharePoint server in the farm (HINT: Run as Administrator).
- Using the shell, navigate to the directory where the two files above are located.
- Run the PowerShell script with a single parameter which is the URL of the site-collection where you wish to apply changes.
.\applydesign.ps1 http://site_collection_URL
The script executes, places the custom Color Palette inside the Theme Gallery (/_catalogs/theme/15) and applies the changes using the "Current" composed look as a shell. This is what the finished product looks like.
If you need further clarification of the script and how it works please leave a comment and I'll do my best to assist.
Thanks for reading!
Can i use the same script for SharePoint Online Site Collection ?
ReplyDeleteHello Viral. The script in this post will not work using SharePoint Online Management Shell. If you are sticking to Composed Looks in SharePoint Online, you can leverage Design Manager and create a design package that way. Once you have a design package created, you can distribute it to other site collections. Keep in mind, you have to activate SharePoint Server Publishing Infrastructure feature for the Design Manager to appear in Site Settings.
DeleteThanks!