Documentset is a hidden gem in SharePoint, it’s a folder with metadata.
This feature can be activated in the site collection features and will add the “Document Set” Contenttype to the site.
In a recent project I had to mass create Documentsets with predefined metadata.

This article is not about how fabulous Documentsets is, it’s about how to mass create Documentsets with PnP PowerShell.
Fist thing first, create a new site content type based on “Document Set”

Add some metadata to your new Contenttype

Add the Documentset to your Document library

When in use, the Documentset will have a different icon than regular folders, an we can assign metadata to the Documentset itself.

The below code is a small portion of a working script to showcase how it can be done. Dependent on your business case, you will need to modify and extend the script to do whatever you need it to do.
#Connect to SharePoint online site
$spcon = Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/site" -Interactive -ReturnConnection
#new docset metadata
$doclibrary = "Shared Documents"
$docsetName = "Documentset 1002"
$docsetContenttype = "My Documentset"
$Year = "1002"
$ResponsiblePerson = "UPN" #UPN of the user
$ResponsibleUnit = "Marketing"
#check if the Documentset exist or not
$docsetexist = Get-PnPFolder -Url "https://tenant.sharepoint.com/sites/sites/$doclibrary/$docsetName" -Connection $spcon -ErrorAction SilentlyContinue
if($docsetexist)
{
#write-host
Write-Host "Documentset exist in library: " $docsetName
}
else
{
#Add-PnP Documentset, then update documentset metadata
Write-Host "Creating Documentset: " $docsetName -BackgroundColor Green
$docset = Add-PnPDocumentSet -List $doclibrary -ContentType $docsetContenttype -Name $docsetName -Connection $spcon
$docsetprop = Get-PnPFolder -Url $docset -Connection $spcon
$docsetprop.Context.Load($docsetprop.ListItemAllFields)
$docsetprop.Context.ExecuteQuery()
#Set docset metadata
Set-PnPListItem -List $doclibrary -Identity $docsetprop.ListItemAllFields.Id -Values @{Year="$Year"; Responsible_x0020_Person="$ResponsiblePerson"; Responsible_x0020_Unit="$ResponsibleUnit"} -Connection $spcon
}
Change the metadata in the script and run it, the results in SharePoint Online is pretty cool.

Hi Jimmy, thanks for the post.
In my case I need to change regular folders to document sets though. Some say, you can´t just change the content type from folder to document set since there might be some steps missing which are run through when setting up a newly document set.
Do you have any idea if you can convert the content type straight forward or if there are is going anything wrong when not creating it from scratch?
Thanks!
LikeLike
Hi Philipp, I haven’t done this before so unfortunately I don’t have much experience. But if possible I’ll recommend you to somehow change the process to create the Docsets directly as this is a pretty special content type.
LikeLike