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
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>)
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])

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