On Sharepoint Online, using Powershell/CSOM, I am iterating through Doc Library folder set, retrieving the Folder.Files, iterating through the files, and trying to match a custom field value in the list item associated with that file.
Microsoft says File.ListItemAllFields should provide all of the fields and values I need, but it isn't retrieving the custom field value that I'm looking for.
Here is a simplified powershell snippet:
# Get Target List
$list = $lists.GetByTitle($Lib + " Library")
$ctx.Load($list)
$ctx.Load($list.RootFolder)
$ctx.ExecuteQuery()
# Get List Folders
$folders = $list.RootFolder.Folders
$ctx.Load($folders)
$ctx.ExecuteQuery()
$folders = $folders | sort Name
foreach ($folder in $folders)
{
$files = $folder.Files
$ctx.Load($files)
$ctx.ExecuteQuery()
foreach ($file in $files)
{
$ctx.Load($file)
$ctx.Load($file.ListItemAllFields)
$ctx.ExecuteQuery()
if($file["IPGroup"] -eq $IPGroup)
{
"File {0} has IPGroup {1}..." -f $file.Name, $file["IPGroup"] | Write-Host -ForegroundColor Green; continue
}
}
}
The custom field "IPGroup" is not being returned by the File.ListItemAllFields property.
What am I doing wrong (this time)?