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.
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.
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,
If we look at the Library settings, we can see all the content types available there.
I am using two CSV Files as input for this script.
Download SCRIPT HERE
Happy Coding.
Sathish Nadarajan.






 
  
 
Leave a comment