How to Remove (hide) Out Of Box – OOB Content Types from Library in SharePoint 2013 using PowerShell


Sathish Nadarajan
SharePoint MVP
Published On :   30 Mar 2015
Visit Count
Today :  1    Total :   7529
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


In one of the requirement, I Added some Content Types to a Pages Document Library. And on the New Document, the list shown like as below.

image

On the above, if you see, the first 4 content types are the default OOB Content Types. The last three, I added.

Now, the customer wanted to see only these three in the drop down and on the EditProperties Page as well.

image

To do that, either we can delete the 4 OOB content types from the Library itself. But even that also, we should not do. That’s the requirement. Then, we need to hide these CTs from display only. For that, I have come up with a PowerShell Script. The script is as below.

 cls
 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".\DocumentLibraryPatch-$LogTime.rtf"
 
 start-transcript $logfile
 
 # Add SharePoint PowerShell Snapin
 
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
     Add-PSSnapin Microsoft.SharePoint.Powershell
 }
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
 #################################################################################################################
 
  
 $CSVFile3 = $scriptBase + "\" + "RemoveOOTBContentTypes.csv"
 $CSVFile2 = $scriptBase + "\" + "ListDetails.csv"
 
 import-csv $CSVFile2 | where {
 
     $web = Get-SPWeb $_.SiteUrl
     $myList = $web.Lists[$_.LibraryName]
     $rootFolder = $myList.RootFolder
     $contentTypeList = $rootFolder.ContentTypeOrder
     $contentTypeList.Clear()
 
 
    import-csv $CSVFile3 | where {
  
         $contentTypeList.Add($myList.ContentTypes[$_.MakeVisibleContentType])
     }
 
     $rootFolder.UniqueContentTypeOrder = $contentTypeList
     $rootFolder.Update()
     $myList.Update()
 
     Write-host "OOTB Content Types are removed successfully"
 }
 stop-transcript
 

After executing the script, the page looks like,

image

 

image

 

If we look at the Library settings, we can see all the content types available there.

image

I am using two CSV Files as input for this script.

Download SCRIPT HERE

Happy Coding.

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

Migratiin Tools for SharePoint