Windows PowerShell provides administrators with the ability to create complex scripts that utilize Cmdlets and .NET code. The Microsoft SharePoint PowerShell snap-in exposes many of the common administrative functions of SharePoint as Cmdlets. For the rest, we can use the server-side object model.
Since composed looks are applied at the site level, it can be cumbersome to apply them to a large number of sites. In this recipe, we are going to use PowerShell to iterate through all of the SharePoint sites in a site collection to apply a composed look.
Follow these steps to apply a composed look to all sites in a site collection using PowerShell:
.ps1
script file.Get-SPSite
Cmdlet:$site = Get-SPSite http://sharepoint/site
foreach
loop to iterate through each SPWeb
in the AllWebs
property of the SPSite
object:foreach ($web in $site.AllWebs)
SPWeb
exists:if ($web.Exists)
ApplyTheme
method:$web.ApplyTheme("/_catalogs/theme/15/Palette015.spcolor", "/_catalogs/theme/15/SharePointPersonality.spfont", "/_layouts/15/images/image_bg011.jpg", $false)
Dispose
method to discard the SPWeb
object:$web.Dispose()
Dispose
method to discard the SPSite
object:$site.Dispose()
PS1
file, for example, applycomposedlook.ps1
../applycomposedlook.ps1
Using PowerShell we can easily create scripts to perform tasks that would normally require a tedious amount of manual work. In this recipe, we iterated through each site in the AllWebs
property of the site collection that we obtained using the Get-SPSite
Cmdlet. For each SharePoint site, we used the ApplyTheme
method to apply our composed look.
The steps performed in PowerShell may also be completed with code using the server-side object model. Follow these steps to apply a composed look to all sites in a site collection with code using the server-side object model:
using
statement:using (var site = new SPSite("http://sharepoint/site")
foreach
loop to iterate through each SPWeb
in the AllWebs
property of the SPSite
object:foreach (var web in site.AllWebs)
SPWeb
exists:if (web.Exists)
ApplyTheme
method:web.ApplyTheme("/_catalogs/theme/15/Palette015.spcolor", "/_catalogs/theme/15/SharePointPersonality.spfont", "/_layouts/15/images/image_bg011.jpg", false);
Dispose
method to discard the SPWeb
object:web.Dispose();
3.149.27.72