Tuesday 13 December 2016

Simple PowerShell script to work with SPListItem fields and data

Using PowerShell to find out about data in SharePoint is par for the course, but making the best use of PowerShell's various cmdlets is something that takes time.

A very powerful cmdlet that I have not made enough use of over the years is Out-GridView.  It gives you a filterable grid of information that lets you control column widths and easily find information.

Example script:

cls;
trap{break;}

$siteUrl = "https://dev01-web.#####.com/sites/its1";
$listTitle = "Pages";

$web = Get-SPWeb $siteUrl;
$list = $web.Lists[$listTitle];
$listItem = $list.Items[0];
$listItem.Fields | Select-Object -Property Title, InternalName, @{Name="Value";Expression={$listItem[$_.Id]}} | Out-GridView

The result is a really useful popup window:



- gb