SharePoint Online: Hide a Content Type using PowerShell

Requirement: Hide a Content Type in SharePoint Online

PowerShell to hide a Content Type in SharePoint Online:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Parameters
$ContentTypeName="Business Contacts"

Try {
    #Get Credentials to connect
    $Cred= Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Get the content type from the web
    $ContentTypeColl = $Ctx.Web.ContentTypes
    #Get the content type to Add
    $CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
        $CType.Group = "_Hidden"

        Write-host "Content Type Set Hidden!" -ForegroundColor Green
        Write-host "Content Type Doesn't Exist!" -ForegroundColor Yellow
Catch {
    write-host -f Red "Error Hiding the Content Type!" $_.Exception.Message

This moves the content type to Hidden group – which hides the content type from site settings >> Site Content Types page! Also, this content type will not be listed in available content types drop down when you try to add any existing content type to a list or library.

To hide a content type from new button drop-down in SharePoint Online list settings page, use: SharePoint Online: Hide Content Type from dropdown

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply