1

I am new to using PowerShell with regards to pulling data from SharePoint using PnPListItem.

I have my code below:

Write-Host "Please enter URL of the SharePoint site:"
$url = Read-Host


Write-Host "Please enter List Name of the SharePoint site:"
$ListName = Read-Host 

Connect-PnPOnline -Url $url -UseWebLogin
Get-PnPListItem -List $ListName

It is getting all the row that I need, the problem is that it returns only the ID, Title, and GUID columns.

I need all the columns in my value display. Any advise?

3

For working with the values in Field use this code. Edited for got dynamically List fields and items with all fields. It returning system fields too, but they are empty here. Hope it helps in some way. I am still using classic SPO commands.

Write-Host "Please enter URL of the SharePoint site:"
$url = Read-Host  

Write-Host "Please enter List Name of the SharePoint site:"
$ListName = Read-Host 

Connect-PnPOnline -Url $url -UseWebLogin

$Fields = Get-PnPField -List $ListName   
$global:FieldsList = ""
foreach($Field in $Fields)
{
    $global:FieldsList = $global:FieldsList + $Field.InternalName + ','
}

$Items = (Get-PnPListItem -List $ListName -Fields $global:FieldsList).FieldValues    
foreach($Item in $Items)
{
    Write-Host $Item.Title -ForegroundColor Yellow
    foreach($Field in $Fields)
    {
        Write-Host $Field.InternalName -ForegroundColor Yellow
        Write-Host $Item[$Field.InternalName]
    }
}
| improve this answer | |
  • Yes I already tried this, but the thing is this should be a reusable script so it should get all the Fields even if I use this in different SP List – Rey Norbert Besmonte Jan 17 '19 at 11:27
  • ok then wait i will update in a few – Zdeněk Vinduška Jan 17 '19 at 11:29
  • Edited, try it, hope it helps. I dont use PnP so much. – Zdeněk Vinduška Jan 17 '19 at 11:53
  • Thanks for this. I used your approach for the base of my Script. Its working now as expected. Cheers – Rey Norbert Besmonte Jan 18 '19 at 6:22
  • Great! :) You're welcome – Zdeněk Vinduška Jan 18 '19 at 7:38
3

You can specify the columns you want to retrieve in the command like given below:

$listItems= (Get-PnPListItem -List $ListName -Fields "Title","Column1", "Column2","Column3","GUID")

Also you can use CAML query in you command, see below given references.

References:

  1. Retrieve SharePoint List Items Using PnP PowerShell.
  2. Get-PnPListItem.
| improve this answer | |
0

You will still need the .fieldValues at the end.

i.e

$listItems= (Get-PnPListItem -List $ListName -Fields "Title","Column1", Column2","Column3","GUID").fieldValues
| improve this answer | |
0

You can only get ID,Title and GUID with this cmdlet Get-PnPListItem no matter how you try and dice it. This is a real let down to most developers that believe this should be this easy to get the rest of the fields and there values in the list. Maybe PNP developers will modify this commandlet so we don't have to use CSOM with a custom CAML Query which is all this is for just these three fields. Useless PNP Cmdlet.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.