SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am sure something wrong with the following code. There are over 400 document-sets in the library and script only shows 8. Please suggest which line is messed up. (At one time I could get this work)

$webUrl = ""
$web = Get-SPWeb $webUrl
$list = $web.Lists["SalesScripts"]

foreach ($item in $list.Items  | Where-Object {$_.Folder -ne $null}) 
    {   $field = $item["Title"]
Write-Host “Provisioning ” $item.Name
$ds = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::GetDocumentSet($item.Folder)
       write-host "something went wrong"
share|improve this question
Hey what happened. I thought I would get some hint from you all (the SP gurus)... – Rosie O'Donnell Nov 10 '11 at 13:51
I totally understand your frustration. Don't expect high quality answer or quick turn around from this site. I face the same dilemma every time I post a question. I usually Google but I know sometimes that does not help. I would help but new to Doc Set. May want to revisit the content types associated with Doc Set. or may want to iterate another way so you get all the doc set that content type="Document Set" (or what ever the name of the doc set content type in your environment) – Mary Rivers Nov 10 '11 at 14:30

Document Set is not a Folder. It inherits from Folder. So I suggest that you enumerate all items in the library and examine their "Content Type" Value then filter on that.

share|improve this answer

The DocumentSet contentType is 0x0120D520

So, to retrieve All your Document Set you can do something like that:

$SelectedItems = $list.Items |? {$_.ContentTypeId.ToString().StartsWith("0x0120D520")}
share|improve this answer

You can simply that code a bit

$site = Get-SPSite "http://somesite"
$web = Get-SPWeb "http://somesite" #gets the root web of somesite
$subweb = Get-SPWeb "http://somesite/someweb" 

foreach($docsetFolder in $rootFolder.SubFolders | where { $_.Name -ne "Forms"})
        foreach ($doc in $docsetFolder.Files)
                    $doc | Select Name, ContentTypeId | Sort Name

Here is another method in C# so you have convert it to PS

public static bool IsDocumentSet(this SPListItem item)
 bool documentSetItem = false;
 DocumentSet documentSet = null;

 if (null != item && item.IsFolder())
  documentSet = DocumentSet.GetDocumentSet(item.Folder);

  if (null != documentSet)
   documentSetItem = true;
 return documentSetItem;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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