Pnp-powershell: Get-PnPListItem -Fields parameter not working as documented.

Created on 28 Nov 2016  路  1Comment  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

Get-PnPListItem -Fields parameter not working as documented.

Expected behavior

If I select the -Fields parameter with a list of fields to be displayed, then I would expect to see those fields displayed.

Actual behavior

PS C:\Program Files\Common Files\microsoft shared\Web Server Extensions15\CONFI
G\POWERSHELL\Registration> Get-PnPListItem -List "Access Requests" -Fields "Tit
le", "ModerationInformation"

Id Title Unique Id
-- ----- ---------
1 By steve for steve.
2 By steve for Chris.
3 By Administrator for Administrator.

PS C:\Program Files\Common Files\microsoft shared\Web Server Extensions15\CONFI
G\POWERSHELL\Registration> Get-PnPListItem -List "Access Requests" -Fields \"Ti
tle\", \"ModerationInformation\"

Id Title Unique Id
-- ----- ---------
1
2
3

Steps to reproduce behavior

see screenshots above

Which version of the PnP-PowerShell Cmdlets are you using?

  • [X ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [ ] PnP PowerShell for SharePoint Online

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

PS C:\Program Files\Common Files\microsoft shared\Web Server Extensions15\CONF
G\POWERSHELL\Registration> Get-Module -Name pnppowershell -ListAvailable

Directory:
C:\Users\pricen\AppData\Local\Apps\SharePointPnPPowerShell2013\Modules

ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.9.1611.0 SharePointPnPPowerShell2013 {Get-PnPTimeZoneId...

How did you install the PnP-PowerShell Cmdlets?

  • [X ] MSI Installed downloaded from GitHub
  • [ ] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

Most helpful comment

Hi Nigel,

Actually the cmdlet does not state that it will _display_ the fields, it just states that it will retrieve the fields. The way CSOM works, for performance reasons, is that it will only retrieve those properties that have explicitly been requested. This will make the payload that will come down from the server smaller, and the server has to do less too. Resulting in more efficient processing and less SQL queries against content database. What the Field parameter does in the cmdlet is only -retrieve- those fields that you are interested in. However, due to the way output works of objects in PowerShell, it will not be able to actually -render- those fields in the list. You can however, write some code in PowerShell that lists those fields if you want to. Taking your initial cmdlet call above:

$items = Get-PnPListItem -List "Access Requests" -Fields Title,ModerationInformation
$items | %{new-object PSObject -Property @{Title=$_["Title"];ModerationInformation=$_["ModerationInformation"]}}
| select Title,ModerationInformation

>All comments

Hi Nigel,

Actually the cmdlet does not state that it will _display_ the fields, it just states that it will retrieve the fields. The way CSOM works, for performance reasons, is that it will only retrieve those properties that have explicitly been requested. This will make the payload that will come down from the server smaller, and the server has to do less too. Resulting in more efficient processing and less SQL queries against content database. What the Field parameter does in the cmdlet is only -retrieve- those fields that you are interested in. However, due to the way output works of objects in PowerShell, it will not be able to actually -render- those fields in the list. You can however, write some code in PowerShell that lists those fields if you want to. Taking your initial cmdlet call above:

$items = Get-PnPListItem -List "Access Requests" -Fields Title,ModerationInformation
$items | %{new-object PSObject -Property @{Title=$_["Title"];ModerationInformation=$_["ModerationInformation"]}}
| select Title,ModerationInformation
Was this page helpful?
0 / 5 - 0 ratings