Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created September 26, 2017 17:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/851df5bfb23734e4d52037732cccc519 to your computer and use it in GitHub Desktop.
Save joerodgers/851df5bfb23734e4d52037732cccc519 to your computer and use it in GitHub Desktop.
Enable and/or Report on the SPWeb Property Settings Related to the HTMLDesign Feature on an SPO Site
$site = "https://contoso.sharepoint.com/sites/publishing-site"
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"
function Get-HtmlDesignFeatureProperties
{
[cmdletbinding()]
param
(
[parameter(Mandatory=$true)][Microsoft.SharePoint.Client.ClientContext]$ClientContext
)
begin
{
$results = @()
$propertyNames = @(
"HtmlDesignViewNameHtmlDesignFiles",
"HtmlDesignViewNameHtmlDesignsAndRelatedFiles",
"HtmlDesignViewNameHtmlMasterPages",
"HtmlDesignViewnameHtmlPageLayouts",
"HtmlDesignViewNameDesignTemplates",
"HtmlDesignViewNameAllDeviceChannelsSimpleListing"
)
}
process
{
$properties = $ClientContext.Site.RootWeb.AllProperties
$ClientContext.Load($properties)
$ClientContext.ExecuteQuery()
foreach( $propName in $propertyNames )
{
$obj = New-Object PSCustomObject -Property @{
Site = $ClientContext.Url
PropertyName = $propName
PropertyValue = "** NOT FOUND **"
}
if( $properties.FieldValues.ContainsKey( $propName.ToLower() ) )
{
$obj.PropertyValue = $properties.FieldValues[$propName.ToLower()]
}
$obj | SELECT Site, PropertyName, PropertyValue
}
}
end
{
}
}
function Enable-HtmlDesignFeature
{
[cmdletbinding()]
param
(
[parameter(Mandatory=$true)][Microsoft.SharePoint.Client.ClientContext]$ClientContext
)
begin
{
$publishingSiteFeatureId = "F6924D36-2FA8-4f0b-B16D-06B7250180FA"
$htmlDesignFeatureId = "a4c654e4-a8da-4db3-897c-a386048f7157"
}
process
{
$features = $ClientContext.Site.Features
$ClientContext.Load($features)
$ClientContext.ExecuteQuery()
if( $( $features | ? { $_.DefinitionId -eq $publishingSiteFeatureId -or $_.DefinitionId -eq $htmlDesignFeatureId } ) )
{
$ClientContext.Site.Features.Add( $htmlDesignFeatureId, $true <# force #>, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None ) | Out-Null
$ClientContext.ExecuteQuery()
}
else
{
Write-Warning "The 'Publishing Site' feature must be activated on '$($ClientContext.Url)' before the 'HTML Design' Feature can be forcefully enabled."
}
}
end
{
}
}
if( -not $credential )
{
$credential = Get-Credential
}
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext( $site )
$clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials( $credential.UserName, $credential.Password )
Enable-HtmlDesignFeature -ClientContext $clientContext
Get-HtmlDesignFeatureProperties -ClientContext $clientContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment