Enable content types in a library or in Site Pages with PowerShell

PowerShell to enable content types in a list. I had an issue where "Site page" content type had dissapeared from some older sites and the content types couldn't be changed as this setting was turned off. If you didn't know, you can't turn on content types in the advanced menu of a site pages library, you have to run a script. 


Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

$url = "SITE"
$username =  "EMAIL"
$password = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $SPOcredentials
$web = $context.Web


$lists = $web.lists
$list = $lists.GetByTitle("Site Pages") #change list if required


Write-Host all good 


Leave a Reply

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