PnP PowerShell and more...

Here I occasionally post about Microsoft 365 Patterns and Practices in general and PnP PowerShell more specifically.

Managing Document Sets with the OfficeDev PnP PowerShell cmdlets

2015-07-21 3 min read PowerShell SharePoint

I just released a couple of new cmdlets to manage document sets in SharePoint. While at the time of writing these cmdlets are not available in the master branch yet, you can still decide to download the dev branch from the GitHub site and compile that one. The cmdlets will be available in the master branch in the August release. The cmdlets work as described below:

There are 4 cmdlets:

Get-PnPDocumentSetTemplate -Identity <DocumentSetPipeBind>
Add-PnPContentTypeToDocumentSet -ContentType <ContentTypePipeBind[]> -DocumentSet <DocumentSetPipeBind>
Remove-PnPContentTypeFromDocumentSet -ContentType <ContentTypePipeBind> -DocumentSet <DocumentSetPipeBind>
          -DocumentSet <DocumentSetPipeBind>
          -Field <FieldPipeBind>
          [-SetSharedField [<SwitchParameter>]]
          [-SetWelcomePageField [<SwitchParameter>]]
          [-RemoveSharedField [<SwitchParameter>]]
          [-RemoveWelcomePageField [<SwitchParameter>]

Creating a document set

A document set is basically nothing but a ‘rich’ Content Type, e.g a content type with additional properties. To create a Document Set you can use the Add-SPOContentType cmdlet:

$parent = Get-PnPContentType -Identity "Document Set"
Add-PnPContentType -Name "PnP Doc Set" -Group "PnP" -ParentContentType $parent

Adding a content type to an existing document set

To add a content type to a document set you have to use the Add-SPOContentTypeToDocumentSet cmdlet. The cmdlets takes a few properties, and there are several ways to provide them:

$ct = Get-PnPContentType -Identity "My Content Type"
$docset = Get-PnPDocumentSet -Identity "My Document Set"
Add-PnPContentTypeToDocumentSet -ContentType $ct -DocumentSet $docset


$ct = Get-PnPContentType -Identity "My Content Type"
$docsetct = Get-PnPContentType -Identity "My Document Set"
Add-PnPContentTypeToDocumentSet -ContentType $ct -DocumentSet $docsetct


Add-PnPContentTypeToDocumentSet -ContentType "My Content Type" -DocumentSet "My Document Set"


Add-PnPContentTypeToDocumentSet -ContentType 0x0101001F1CEFF1D4126E4CAD10F00B6137E969 -DocumentSet 0x0120D520005DB65D094035A241BAC9AF083F825F3B

Of course you can also mix the type of parameters.

Setting the Shared Fields or Welcome Page fields on the document set

You can set certain fields to be shared througout the document set or have certain fields available on the document set welcome page. It is important that you first add those fields to a content type that has been added to the document set. Then with the Set-SPODocumentSetField cmdlet you can set those fields as follows:

Set-PnPDocumentSetField -DocumentSet "My Document Set" -Field "My Field" -SetSharedField -SetWelcomePage

The cmdlet above will add the “My Field” field to a document set called “My Document Set” and sets it as a Shared Field and it will make the field available on the Welcome Page. Like the other cmdlets, you can mix and match the values of the DocumentSet and Field parameters to suite your requirements, e.g. you can send in a name, an actual field or document set template object that you retrieved with one of the other cmdlets, or you can send in an id of a field or document set content type.

To remove a field from the welcome page, but keep it as a shared field after you entered the cmdlet above:

Set-PnPDocumentSetField -DocumentSet "My Document Set" -Field "My Field" -RemoveWelcomePageField