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

Sathish Nadarajan
 
Solution Architect
March 30, 2015
 
Rate this article
 
Views
10830

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.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment