Generic PowerShell Function to Create a Document Set SharePoint 2013 On-Prem

The function accepts 4 paramters the Site Url, the Library name where the Document Set will be created, the Content Type of the Document Set and finally the Name of the Document Set.
To set properties for the Document Set, and simple modification would be to include a key pair Hash table, the function declares an empty one ($dsProps) 

Example would be:
[hashtable] $dsProps = @{"Key" = "Value";"Key" = "Value";}


The function:
function createDocumentSets([string]$SiteUrl, [string]$LibraryName, [string]$CTName, [string]$dsName) { [Microsoft.SharePoint.SPWeb]$oWeb = Get-SPWeb $SiteUrl [Microsoft.SharePoint.SPList]$oLibrary = $oWeb.Lists[$LibraryName] if($oLibrary.Title -eq $LibraryName) { [Microsoft.SharePoint.SPContentType]$oCT = $oLibrary.ContentTypes[$CTName] if($oCT.Name -eq $CTName) { [Hashtable]$dsProps = @{} [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]$newDs =
Write-Host "`tCreating '$dsName' ($CTName) in Library '$LibraryName' @ '$SiteUrl'" } else { Write-Host "[ERROR] Getting Content Type '$CTName' on Library '$LibraryName' @ '$SiteUrl'" } } else { Write-Host "[ERROR] Getting Library '$LibraryName' @ '$SiteUrl'" } $oWeb.Dispose() }

No comments :

Post a Comment