kwizcom banner advertisement

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
$SiteURL="https://crescent.sharepoint.com"
$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
    $Ctx.Load($ContentTypeColl)
    $Ctx.ExecuteQuery()
 
    #Get the content type to Add
    $CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
    {
        $CType.Group = "_Hidden"
        $CType.Update($True)
        $Ctx.ExecuteQuery()

        Write-host "Content Type Set Hidden!" -ForegroundColor Green
    }
    else
    {
        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 dropdown in SharePoint Online site settings page, use: SharePoint Online: Hide Content Type from dropdown
SharePoint Online: Hide a Content Type using PowerShell SharePoint Online: Hide a Content Type using PowerShell Reviewed by Salaudeen Rajack on July 27, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.