Inspect SharePoint list columns

This is a PowerShell script (op-prem) I use a lot to inspect SharePoint list columns.

There are also great third party tools such as SPI-Insider and SharePoint Manager to do a deep-inspection of your SharePoint site. But I find that this simple PowerShell is also a great method to quickly inspect a list without starting a desktop application or browser plugin.

Preview

shadow rotate

Usage

  • First parameter is the URL of the site
  • Second is the name of the list > If no list is found, all lists on the site will be displayed
  • Third (optional) list item ID, if no ID is supplied all list items in the list will be displayed
  • Fourth (optional) filter on the list column names

Code

 1# Copyright (C) www.jurjan.info - All Rights Reserved (MIT License)
 2
 3param(
 4	[Parameter(Mandatory=$True,Position=1)] [string]$url,
 5	[Parameter(Mandatory=$True,Position=2)] [string]$listTitle,
 6	[Parameter(Mandatory=$False,Position=3)] [string]$listItemID,
 7	[Parameter(Mandatory=$False,Position=4)] [string]$filter
 8)
 9
10Write-Host "usage: ListItems.ps1 [url] [listTitle] [listItemID] [filter]       (listItemID and filter is optional)" -ForegroundColor Yellow -BackgroundColor Green
11if ($null -eq (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue))
12{
13    Add-PSSnapin Microsoft.SharePoint.PowerShell
14}
15
16try {
17	$web = Get-SPWeb $url -ErrorAction SilentlyContinue
18	$list = $web.Lists[$listTitle]
19} catch {
20	Write-Host "$url does not exist" -ForegroundColor Red
21	break
22}
23
24if(-not $listItemID)
25{
26	Write-Host "ListItemID was not supplied, listing all listitems" -BackgroundColor DarkGreen -ForegroundColor Black
27	if($null -eq $list)
28	{
29		Write-Host "No list found, showing all available lists" -ForegroundColor Red
30		$web.Lists | ForEach-Object {
31			Write-Host $_.Title
32		}
33	}
34	$list.Items | Format-Table
35}
36else 
37{
38	Write-Host "Showing specific ListItem: " -BackgroundColor DarkGreen -ForegroundColor Black
39	try {
40		$listItem = $list.GetItemByID($listItemID)
41	} catch {
42		Write-Host "Listitem $listItemID does not exists" -ForegroundColor Red
43		break
44	}
45	
46	if(-not $filter)
47	{
48		$listItem.Fields | ForEach-Object {
49	 		Write-Host $_.Title "[" $_.InternalName "]`t`t" -NoNewline -ForegroundColor Yellow -BackgroundColor DarkRed
50	 		Write-Host $listItem[$_.InternalName] -ForegroundColor Yellow -BackgroundColor Red
51		}
52	}
53	else
54	{
55		$listItem.Fields | Where-Object {$_.InternalName -match $filter} | ForEach-Object {
56	 		Write-Host $_.Title "[" $_.InternalName "]`t`t" -NoNewline -ForegroundColor Yellow -BackgroundColor DarkRed
57			Write-Host $listItem[$_.InternalName] -ForegroundColor Yellow -BackgroundColor Red
58		}
59	}
60}

open raw file