Retrieve Allowed Content Types from a Document Set Using PowerShell

This is more of a brain dump than anything else. This week at a client, I had to simulate their environment which was becoming very slow when loading a specific library. That particular library had over 450 Content Types associated with it, but we were specifically interested in figuring out how many allowed content types were included in a given content type. The following lines of PowerShell will allow you to retrieve information about how many content types are included within a Document Set at a library level. It is important to note that the script needs to retrieve an instance of that document set content type in order to determine how many associated allowed content types there are.

Add-pssnapin microsoft.sharepoint.powershell -EA SilentlyContinue

$webUrl = Read-Host "URL of the site"
$libraryName = Read-Host "Name of the Library"
$docSetName = Read-Host "Name of the Document Set Item"


$web = Get-SPWeb $webUrl
$lib = $web.Lists[$libraryName]
$docSetInstance = $lib.Folders | ?{$_.Title -eq $docSetName}
$docSetTemplate = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($docSetInstance.Folder)
$numberOfAllowedContentTypes = $docSetTemplate.ContentTypeTemplate.AllowedContentTypes.Count

One thought on “Retrieve Allowed Content Types from a Document Set Using PowerShell

  1. As far as I remember, was it not possible to identify contenttypes by hierarchy? Are you trying to get those or the fields of a contenttype?
    If you were looking for all dependend (by hierarchy) contenttypes, it should be possible to find them by using a -like operator plus wildcard in powershell:
    $ContentTypes = $List.ContentTypes | Where {$_.Name -Like “0x0101*”}

Leave a Reply to Nils Cancel reply

Your email address will not be published. Required fields are marked *