SharePoint PowerShell PnP - How to get list item by Item ID using GetItemById, Get-PnPListItem


How to query and retrieve SharePoint List Item by Itemd ID using PowerShell / Management Shell / PnP PowerShell ?

There are multiple ways
GetItemById()
Get-PnPListItem (PnP)

Use below PowerShell command to retrieve SharePoint List Item using the Item ID. This uses GetItemById() which takes in the ItemId as a parameter.

You can modify the below code for other requirements but the core logic remains the same.

Using GetItemById()

$web = Get-SPWeb <SITE URL>
$list = $web.GetList("<LIST NAME>")
$list.GetItemById(<ITEM ID>)
where,
SITE URL = URL of SharePoint Site (string)
LIST NAME = Name of SharePoint List (string)
ITEM ID = Number of Item Id (integer)

Using PnP Get-PnPListItem

Get-PnPListItem -List [List Name] -Id [ID]

Using GetItemById() for SharePoint Online

$list = $Context.web.Lists.GetByTitle("[List Name]")
$listItem = $List.GetItemById([ID])
$context.Load($listItem)
$context.ExecuteQuery()

You can further update the script further to filter and query only required columns/fields.



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap