pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
663 stars 343 forks source link

[BUG] ListItemAllFields property is empty for Get-PNPFolderItem #4139

Open sg1888 opened 1 month ago

sg1888 commented 1 month ago

Reporting an Issue or Missing Feature

When I am using Get-PNPFolderItem, the items returned do not have ListItemAllFields data. It just shows up as an empty output. Unlike the Get-PnPFolder command, you also can't load the properties using -Includes ListItemAllFields.

Related bugs: https://github.com/pnp/PnP-PowerShell/issues/2061

2679

Expected behavior

I would expect to see the Item ID, Title and GUID populated. The Item ID is critical as that is what many PNP commands require to edit / modify files.

Actual behavior

I do not see any properties. The ID, Title, and GUID are empty. Get-PNPFolderItem

Steps to reproduce behavior

Connect-PnPOnline -url $url -Credentials $Credentials
$Items = Get-PNPFolderItem -FolderSiteRelativeUrl $PathToFolder
$Items[1].ListItemAllFields

What is the version of the Cmdlet module you are running?

2.5.0

Which operating system/environment are you running PnP PowerShell on?

ToddKlindt commented 1 month ago

Because we don't know how big each object is, the PnP cmdlets usually just pull a select few properties down for each object. While that's a drag, there is a way to get the other properties. See if using Get-PnPProperty works for you. It would look like this:

$a = Get-PnPFolderItem -FolderSiteRelativeUrl "Documents 2" -Recursive $a | foreach {Get-PnPProperty -ClientObject $_ -Property ListItemAllFields}

Now when you run $a[5].ListItemAllFields it's populated.

I assume you already know about Get-PnPListItem, but I thought I'd mention it just in case.

sg1888 commented 1 month ago

Because we don't know how big each object is, the PnP cmdlets usually just pull a select few properties down for each object. While that's a drag, there is a way to get the other properties. See if using Get-PnPProperty works for you. It would look like this:

$a = Get-PnPFolderItem -FolderSiteRelativeUrl "Documents 2" -Recursive $a | foreach {Get-PnPProperty -ClientObject $_ -Property ListItemAllFields}

Now when you run $a[5].ListItemAllFields it's populated.

I assume you already know about Get-PnPListItem, but I thought I'd mention it just in case.

Thank you for the suggestion! The Get-PnPProperty does indeed work, but it is slow - I have 4 million files to process, so all those milliseconds adds up. I'm not too familiar with the inner workings of PnP cmldlets, but was hoping that the ID would be included as it's required for so many other cmdlets (such as Set-PnPListItem, etc).

I'm familiar with Get-PnPListItem, but I haven't found a way to limit what it loads. I tried using the -FolderServerRelativeURL using the line below:

Get-PnPListItem -list "Documents" -FolderServerRelativeURL "/sites/somerelativeurl" -PageSize 10000

But whenever I do, it ignores the PageSize and the operation fails since it exceeds the list view threshold. Is there a better way to use Get-PnPListItem to isolate only certain folders on a large list?

ToddKlindt commented 1 month ago

I think CAML might be the way you need to go. Look at Get-PnPListItem examples #5 and #6 for an idea what that looks like. I had ChatGPT throw together a couple of things for me but I couldn't get it to work the way you want. I'm not a CAML expert though. You might have better luck.