How to set AlternateCSS URL for s sharepoint subsites in SharePoint Online/Office 365 using CSOM?

Hello SharePointers,

Here is the CSOM code to set AlternateCSS URL for s sharepoint subsites in SharePoint Online/Office 365 using CSOM.

SiteColUrl = “https://mysharepointsite/url”
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
$Context.Credentials = $spoCredentials

$Web = $Context.Web
$allwebs = $rWeb.Webs

$Context.Load($allwebs)
$Context.ExecuteQuery()

foreach($web in $allwebs)
{
$web = $Context.web
$Context.Load($web)
$Context.ExecuteQuery()

$alternateCssUrl = “test.css”

$web.AlternateCssUrl = $alternateCssUrl
$web.AllProperties[“__InheritsAlternateCssUrl”] = $true
$web.Update()
$Context.ExecuteQuery()
}

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *