I have the following script which should output the name of the content type for each list item however it is not, where am I going wrong? The output for both Id and Name is just a blank line, clearly loops through each item yet doesn't find the content type field
$qCommand = @"
<View Scope="RecursiveAll">
<Query>
<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)
{
$CT = $item.ContentType
write-host $item.ContentType.Id
write-host $item.ContentType.Name
if($CT -eq "Land")
{
$item["FileLeafRef"] | Out-File "C:\temp\test.csv" -append
}
}