I have a Document Library contains multiple Document Sets, each of the Document Sets contains Files.

Document Library ----> Document Set ----> Files

My objective is to query all File Name only across Document Sets.

here are my code:

function Get-SPItem{
    $web = Get-SPWeb $webUrl
    $documentsLib = $web.Lists[$libraryName]

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

    $query = New-Object Microsoft.SharePoint.SPQuery

    #$viewFields = "<FieldRef Name='Title'/><FieldRef Name='Name'/>"
    $query.Query = $camlQuery
    $query.ViewAttributes = "Scope='Recursive'"

    $queryResults = $documentsLib.GetItems($query)

    foreach($item in $queryResults){
        $filename =  [io.path]::GetFileNameWithoutExtension($item.Name)
        Write-Host $filename


The code above return both Document Set Name and Files Name, which going to be extra row and how can I eliminate Document Set Name?

Thank you in advanced :)

1 Answer 1


Use the <BeginsWith> element in your query to select items that inherit from Document (0x0101...). Document Sets inherit from folder (0x0120...)


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.