Get List Items from a SharePoint View in PowerShell

Requirement: Get all list items from a SharePoint view in PowerShell

sharepoint powershell get items in listview

PowerShell to Get Items in a SharePoint List view

When you are working with SharePoint, there are times when you need to get a list of items from a view, rather than getting all of the items in the list. Whether you’re looking to export data or just need some way to automate getting data from a SharePoint view for reporting or other purposes, PowerShell is your answer! In this post, we’re going to take a look at how you can use PowerShell to get items from a SharePoint list view.

Here is the PowerShell script example to get list items from a SharePoint view:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteUrl="https://intranet.crescent.com" 
$ListName = "Invoice"
$ViewName = "2014 Invoice"

#Get Web and List objects
$web = Get-SPWeb $SiteURL
$list = $web.Lists[$ListName]

#Get the View
$view = $list.Views[$ViewName]

#Get All Items from the View
$items = $list.GetItems($view)

foreach($item in $items)
{
    write-host $item["Title"]
}

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “Get List Items from a SharePoint View in PowerShell

  • Thank you for sharing the Script. Very useful as always. I am getting below strange error. Any suggestion would be appreciated.

    Cannot index into a null array.
    At line:23 char:5
    + $ExportItem | Add-Member -MemberType NoteProperty -name “Title” -value $_[“T …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *