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)

$docLib = "NewProduct"
$site=Get-SPSite $siteURL
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

            # changing folder type to Document Set type
            $newDocumentSet.Item["ContentTypeId"] = $cType.Id
            $newDocumentSet.Item["HTML File Type"] = "SharePoint.DocumentSet"


# 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)                       



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.

2 Answers 2


Just by looking at your code.


and $docLib is string?

$docLib = "NewProduct"

maybe this would work



[Microsoft.SharePoint.SPFolder]$targetFolder = $web.GetFolder($DocSetURL)
  • hmm. still gettting same error. Exception calling "Create" with "4" argument(s): "<nativehr>0x80070002</nativehr><nativestack></nativestack>" At C:\Dev\PowerShell\MoveFiles2DocSet.ps1:38 char:91 + $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create <<<< ($targetFolder, $DocSet,$cType.Id,$docsetProperties) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Sep 14, 2011 at 20:19
  • Please update your original question with an updated code sample to reflect Vedran's solution. Your code above does not have 38 lines (though your error occurs at line 38). Sep 14, 2011 at 20:24
  • Actually the error on this line $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.RootFolder,$DocSet,$cType.Id,$docsetProperties) Sep 14, 2011 at 20:37
  • I have bunch of comments that's why my line and posted line are out of sync Sep 14, 2011 at 20:38
  • Well Verdan has you on the right track. First, make sure none of your parameters are null (write them out to the screen to ensure their values), and make sure that their types are correct. Sep 14, 2011 at 20:47

I'm kind of late to this particular party, but while researching my own issue with document sets appearing as simple folders I came across this blog entry ( http://aknauer.blogspot.com/2011/06/document-sets-und-powershell.html ) which contained this valuable nugget:

"It is also important that you select the content type $cType from the collection of the list and not from the collection of the Web. Otherwise, rather than just a document set a new folder is created."

I switched my content type assignment from the web collection (as Mala had done) to the list collection (as Andreas suggests) and my problem was resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.