Get-PnPListItem not retrieving column data

Brass Contributor
I'm having an issue with Get-PnPListItem where I'm getting the content of a list. I'm wanting to make a change on each item in the list. For some reason even when telling the command which columns to lookup some are empty. However if I use Get-PnPListItem with the Id switch it does retrieve all the needed column data. I've done the script to use Get-PnPListItem to get me the number of items then go over them again with the ID to get the data but this is so slow. Is there something I'm missing from Get-PnPListItem I can do to ensure the column data I want is retrieved without having to iterate over each item individually with Get-PnPListItem?
3 Replies

@David Jenkins Hi David, I will answer this in two parts First get all the list columns:

 

Use the below script:

 

Connect-PnPOnline https://yourorg.sharepoint.com/sites/demo/ -cred $cred
$ListName = "List1"
$Fields = Get-PnPField -List $ListName
$global:FieldsList = ""
$i =1
foreach($Field in $Fields)
{
$global:FieldsList = $global:FieldsList + $Field.InternalName + ','
Write-Host "Field Number " $i $Field.InternalName
$i++
}

 

Once you have all the columns select the columns you need :

Then use the below code:

 


Connect-PnPOnline https://yourorg.sharepoint.com/sites/demo/ -cred $cred
$ListName = "List1"
$Fields = Get-PnPField -List $ListName
$Items= (Get-PnPListItem -List $ListName -Fields "Title","GUID", "Modified","Created","ID")
$i=1
foreach($Item in $Items)
{
Write-Host "Item #" $i -ForegroundColor Yellow
Write-Host "Title :" $Item["Title"]
Write-Host "GUID :"$Item["GUID"]
Write-Host "Modified :"$Item["Modified"]
Write-Host "Created :"$Item["Created"]
$i++
}

Final output will be something like this

clipboard_image_0.png

I have actually done this already. Pretty much the same procedure to determine the internal name just in case it was different.

I tested by adding the responses to an object and reviewing. Unless I did as mentioned it would always miss a few columns.

Part of the reason I'm messing with the columns is that it is a migration from 2013 and has many lookup columns. Since PowerApps doesn't support that many lookups I have to swap the lookups for textboxes and go back with PowerApps and add DDLs. I'm wondering if the restrictions on lookup columns is causing the issue. I noticed in views I was not able to add all the lookup columns either.

@David Jenkins Sorry I could not help! If it would be me then, even I will first query the required items and make an array of ids for which I need to run some updates. Then I would just pass that array to do the intended business operation. I tried at my end but unfortunately I could not replicate but I am trying in a new site not in an migrated site. That might be the difference. Best of luck :)