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.

Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency