Create Document Set if it does not exist (Powershell)
-
22-10-2019 - |
Question
Adding If doc set does not exist then create doc set. What would be the syntax for looking up document set then create (if does not exists)
### Create new Document Set
$siteURL="http://intra.colgate.com/sites/vendors"
$docLib = "SOA"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
$DocSetName = $item["Vendor"]
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
Solution
I'm not sure if I'm answering the right question, but I used this method to check if Doc Set (folder) exists, and if not, create:
[Microsoft.SharePoint.SPFolder]$targetFolder = $rootWeb.GetFolder($targetDocLib.RootFolder.ServerRelativeUrl + "/$docSetName")
if (-not $targetFolder.Exists)
{
# create
}
This approach worked for me.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange