Powershell to read SharePoint 2016 List

Hello. I have a SharePoint 2016 list which we currently extract into a CSV file and then read with our PowerShell script. The list has about 100 different columns. I would like to read directly from the SharePoint list using my PowerShell program.

I’ve made some progress in that I can log onto the system, get a list of fields, and then run the Get-PnPListItem to see the rows. Get-PnpListItem returns just 3 columns (ID, Title, and GUID). Now I want to load the actual list data into an array so I can work with it in my script. How can I do this? Thank you in advance!!!

$credential = Get-Credential
Connect-PnPOnline –Url "https://mysite.com/sites/mpgxp/tech" –Credentials $credential
Get-PnPField -List "MPGXP Server App List" # Get a list of available fields
Get-PnPListItem -List "MPGXP Server App List" # Read the items in the list

If you are saying this is returning a table of ‘ID, Title, and GUID’, then it is already an array of row information and you can select any row using it’s index number.

$PnPListItems[0]

Are saying you want put each column in a separate array and the do X or Y with it.

If you are saying, the ‘ID, Title, and GUID’ come back as a list vs a table, then you can use the -join, to covert each row to table, or use a custom object to make each a table.

But I may be missing your point / use case, so, clarify as needed.

I’m guessing that the root issue is that the data returned by PnPListItem.FieldValues is a dictionary and that you want to take it to the next step by interacting with it as an object with attributes.

The following is working for me to pull all list items and store them into a PSObject array.

https://gist.github.com/jeremytbrun/06262b1ac42e239543ba9e8d18a19a48

This worked. Thank you so much!!

I guess my only follow up question would be this. Pulling by InternalNames works, but is there a way to swap the column names InternalNames for the Title?

Paul

I edited my script sample above. Getting the friendly title of each Field seemed a little bit more involved but not impossible. I found that some built-in fields have duplicate names. For those my code adds an incremented " (#)" suffix to each new duplicate field name. I doubt these fields are going to be of use to you since they seem to be built-in and have little to no data though. If you wanted to only process specific fields you could add a Where-Object to your Get-PnPField command.

@Jeremy Brun, thank you very much for this. It worked perfectly!