Forum Discussion
Get-PnPListItem not retrieving column data
3 Replies
ComputerHabit 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
- ComputerHabitBrass ContributorI 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.ComputerHabit 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 🙂