문제

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?

도움이 되었습니까?

해결책

The correct field value to use is FileLeafRef for folder names

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

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top