0

I have the following powershell:

$list = $ctx.Web.Lists.GetByTitle("Documents")
$ctx.Load($list)
$ctx.ExecuteQuery()
## View XML
$qCommand = @"
<View>
    <Query>
        <Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>Folder</Value></Eq></Where>
        <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
    </Query>
    <RowLimit Paged="TRUE">5000</RowLimit>
</View>
"@
## Page Position
$position = $null

## All Items
$allItems = @()
Do{
    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $camlQuery.ListItemCollectionPosition = $position
    $camlQuery.ViewXml = $qCommand
## Executing the query
    $currentCollection = $list.GetItems($camlQuery)
    $ctx.Load($currentCollection)
    $ctx.ExecuteQuery()

## Getting the position of the previous page
    $position = $currentCollection.ListItemCollectionPosition

# Adding current collection to the allItems collection
    $allItems += $currentCollection
}
# the position of the last page will be Null
Until($position -eq $null)
$results = ""
foreach($item in $allItems){
write-host $item["Name"]
$item.Name | Out-File "C:\temp\test.csv" -append

}

Which should output the name of each folder, however it is just a blank line. I have tested the script with outputting the ID and that matches with the folders that are in the library it is just an issue when i try outputting the Name. Any ideas where i am going wrong?

1

2 Answers 2

3

The correct field value to use is FileLeafRef for folder names

Modify your code as write-host $item["FileLeafRef"] should output the folder name

0

Change $item["Name"] to $item["Title"] or $item.Name (don't have have connection to SP atm to check so advise if from top of my head)

2
  • Folders don't have a title field? also i tried this and produces the same result Commented Nov 14, 2018 at 13:58
  • I updated my answer try with $item.Name Commented Nov 14, 2018 at 13:59

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.