Get-PnPListItem

Tip

We encourage you to make improvements to this documentation. Please navigate to https://github.com/pnp/powershell/blob/dev/documentation/Get-PnPListItem.md to change this file.

Retrieves list items

Syntax

Get-PnPListItem
   [-List] <ListPipeBind>
   [-FolderServerRelativeUrl <String>]
   [-Fields <String[]>]
   [-PageSize <Int32>]
   [-ScriptBlock <ScriptBlock>]
   [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPListItem
   [-List] <ListPipeBind>
   [-Id <Int32>]
   [-Fields <String[]>]
    [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPListItem
   [-List] <ListPipeBind>
   [-UniqueId <Guid>]
   [-Fields <String[]>]
    [-Connection <PnPConnection>]
   [<CommonParameters>]
Get-PnPListItem
   [-List] <ListPipeBind>
   [-Query <String>]
   [-FolderServerRelativeUrl <String>]
   [-PageSize <Int32>]
   [-ScriptBlock <ScriptBlock>]
   [-Connection <PnPConnection>]
   [<CommonParameters>]

Examples

EXAMPLE 1

Get-PnPListItem -List Tasks

Retrieves all list items from the Tasks list

EXAMPLE 2

Get-PnPListItem -List Tasks -Id 1

Retrieves the list item with ID 1 from the Tasks list

EXAMPLE 3

Get-PnPListItem -List Tasks -UniqueId bd6c5b3b-d960-4ee7-a02c-85dc6cd78cc3

Retrieves the list item with UniqueId or GUID bd6c5b3b-d960-4ee7-a02c-85dc6cd78cc3 from the tasks lists

EXAMPLE 4

(Get-PnPListItem -List Tasks -Fields "Title","GUID").FieldValues

Retrieves all list items, but only includes the values of the Title and GUID fields in the list item object

EXAMPLE 5

Get-PnPListItem -List Tasks -Query "<View><Query><Where><Eq><FieldRef Name='GUID'/><Value Type='Guid'>bd6c5b3b-d960-4ee7-a02c-85dc6cd78cc3</Value></Eq></Where></Query></View>"

Retrieves all available fields of list items based on the CAML query specified

EXAMPLE 6

Get-PnPListItem -List Tasks -Query "<View><ViewFields><FieldRef Name='Title'/><FieldRef Name='Modified'/></ViewFields><Query><Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'><Today/></Value></Eq></Where></Query></View>"

Retrieves all list items modified today, retrieving the columns 'Title' and 'Modified'. When you use -Query, you can add a clause to retrieve specific columns (since you cannot use -Fields)

EXAMPLE 7

Get-PnPListItem -List Tasks -PageSize 1000

Retrieves all list items from the Tasks list in pages of 1000 items

EXAMPLE 8

Get-PnPListItem -List Tasks -PageSize 1000 -ScriptBlock { Param($items) $items.Context.ExecuteQuery() } | ForEach-Object { $_.BreakRoleInheritance($true, $true) }

Retrieves all list items from the Tasks list in pages of 1000 items and breaks permission inheritance on each item

EXAMPLE 9

Get-PnPListItem -List Samples -FolderServerRelativeUrl "/sites/contosomarketing/Lists/Samples/Demo"

Retrieves all list items from the Demo folder in the Samples list located in the contosomarketing site collection

Parameters

-Connection

Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

Type:PnPConnection
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Fields

The fields to retrieve. If not specified all fields will be loaded in the returned list object.

Type:String[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-FolderServerRelativeUrl

The server relative URL of a list folder from which results will be returned.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Id

The ID of the item to retrieve

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-List

The list to query

Type:ListPipeBind
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-PageSize

The number of items to retrieve per page request.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Query

The CAML query to execute against the list

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ScriptBlock

The script block to run after every page request.

Type:ScriptBlock
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-UniqueId

The UniqueId or GUID of the item to retrieve

Type:Guid
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False