Question

I have a SharePoint 2013 environment where I want to apply a single Alternate CSS file across all site collections and subsites. I am using the following method. When I run this I receive a single error, the Alternate CSS is applied to all sites and subsites EXCEPT on the root site collection. Any ideas how I can get this to work for the root site collection as well?

$Webapp = Get-SPWebApplication "http://MyServer/"

$Sites = $Webapp.sites.url
foreach ($site in $sites)
{
  $web = Get-SPWeb $site
  $cssurl = "/SiteAssets/DevColorChange.css"
  $web.AlternateCssUrl = $cssurl
  $web.AllProperties["__InheritsAlternateCssUrl"] = $True
  $web.Update()
}

ERROR:

Exception calling "Update" with "0" argument(s): "Specified data type does not match the current data type of the property." At line:10 char:1 + $web.Update() + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPInvalidPropertyException

Was it helpful?

Solution

Get-SPWebApplication "http://MyServer/" | Get-SPSite -Limit All | Get-SPWeb -Limit All | % { $_.AlternateCssUrl = ($_.Site.Url + "/SiteAssets/DevColorChange.css");$_.Update() }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top