I am receiving this error on following line
Exception calling "Create" with "4" argument(s): "Value cannot be null. Parameter name: parentFolder" At x:\Dev\PowerShell\MoveFiles2DocSet.ps1:29 char:91 + $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create <<<< ($docLib.RootFo lder,$DocSet,$cType.Id,$docsetProperties) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.RootFolder,$DocSet,$cType.Id,$docsetProperties)
$siteURL="http://intranet.colgate.com/sites/blazingWhite"
$docLib = "NewProduct"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
## Create document set if it does not exists
$DocSet = $item["CounterParty"]
$DocSetURL = $siteURL + "/" + $docLib + "/" + $DocSet
$docLibURL = $siteURL + "/" + $docLib
[Microsoft.SharePoint.SPFolder]$targetFolder = $web.GetFolder($DocSetURL)
[Microsoft.SharePoint.SPFolder]$doclibFolder = $web.GetFolder($docLibURL)
Write-Host ""
Write-Host $DocSet
Write-Host $targetFolder
Write-Host $doclibFolder
if (-not $targetFolder.Exists)
{ # Create Doc Set
# Get Document Set Content Type from list
$cType = $web.ContentTypes["Document Set"]
# Create Document Set Properties Hashtable
[Hashtable]$docsetProperties = @{"Title"=$DocSet}
$docsetProperties = @{"Description"=$DocSet}
$docsetProperties = @{"CounterParty"=$DocSet}
Write-Host $cType.Id
Write-Host $docsetProperties
Write-Host ""
# Create new Document Set
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($doclibFolder,$DocSet,$cType.Id,$docsetProperties)
Write-Host "Document set created " $newDocumentSet
if($newDocumentSet.Exists)
{
# changing folder type to Document Set type
$newDocumentSet.Item["ContentTypeId"] = $cType.Id
$newDocumentSet.Item["HTML File Type"] = "SharePoint.DocumentSet"
$newDocumentSet.Item.Update()
}
}
# move file(s) to the document set
Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
$collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/" + $collFiles[$count-1].Name, $true)
$count--
}
#dispose:
$web.Dispose();
$site.Dispose();
Edit:
The above code is working except document set looks like Folder instead of blue doc set icon. Can anyone shed some light on this please.