Search This Blog

Monday, September 2, 2013

Applying Master Pages and CSS for SharePoint Sites using Powershell

Applying Master Pages and CSS.

$Webapp = Get-SPWebApplication "http://site url"
$Sites = Get-SPSite -ContentDatabase SPPRD_PORTAL_CONTENT1

foreach ($site in $sites)
{
$web = Get-SPWeb $site.url
if ($site.url -eq ""http://site url/demo"

$web.MasterUrl = "/_catalogs/masterpage/v4.master";
$web.CustomMasterUrl = "/_catalogs/masterpage/v4.master"; 

else {
$cssurl = $web.Url + "/Style%20Library/custom.css";
$web.MasterUrl = "/_catalogs/masterpage/custom.master";
$web.CustomMasterUrl = "/_catalogs/masterpage/custom.master";
$web.AlternateCssUrl = $cssurl }
Write-Host $cssurl
$web.Update()
Write-Host "Master Page and CSS updated at:" $Sites.Url -foregroundcolor Red


Applying CSS
$Webapp = Get-SPWebApplication "http://sute url/"

$Sites = $Webapp.sites.url
foreach ($site in $sites)
{
$web = Get-SPWeb $site
$cssurl = $web.url + "/Shared%20Documents/custom.css"
$web.AlternateCssUrl = $cssurl
Write-Host $cssurl
$web.Update()
}
Write-Host " CSS updated at:" $Sites.Url -foregroundcolor Red

Applying Alternate CSS

$web = Get-SPWeb http://site url/
$web.AlternateCssUrl = "/Style Library/CustomStyles/custom.css"
$web.AllProperties["__InheritsAlternateCssUrl"] = $True

$web.Update()
Write-Host " CSS updated at:" $Sites.Url -foregroundcolor Red

No comments:

Post a Comment