There are many column values associated with a single item in SharePoint that are not easily visible using the browser UI or SharePoint Designer – for example, the item GUID, Content Type ID, various paths and URLs to the item, and others. Sometimes, it can also be handy to view a list of internal column names and values for determining what to use in content queries, data views, PowerShell scripts, XSLT, etc.
The script below enables you to specify a single item or file in a list or document library and output a table containing a full list of the column display names, internal names, and their associated values for the item.
First, run the following script:
function Get-SPItemValues {
#Ask for the web, list and item names
$WebName = Read-Host "Please enter the web address:"
$ListName = Read-Host "Please enter the list or library name:"
$ItemName = Read-Host "Please enter the item title or file name:"#Set up the object variables
$web = Get-SPWeb $WebName
$list = $web.Lists[$ListName]
[string]$queryString = $null#Check if the item is a file or list item and run a different query accordingly
if ($list.BaseType -eq "DocumentLibrary") {
$queryString = "<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + $ItemName + "</Value></Eq></Where>"
}
else
{
$queryString = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + $ItemName + "</Value></Eq></Where>"
}#Create the CAML query to find the item
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = $queryString
$item = $list.GetItems($query)[0]#Walk through each column associated with the item and
#output its display name, internal name and value to a new PSObject
$item.Fields | foreach {
$fieldValues = @{
"Display Name" = $_.Title
"Internal Name" = $_.InternalName
"Value" = $item[$_.InternalName]
}
New-Object PSObject -Property $fieldValues | Select @("Display Name","Internal Name","Value")
}#Dispose of the Web object
$web.Dispose()
}
Once you have run the script, you can call the function using the following command:
Get-SPItemValues
You will be then asked to enter a site name….
….a list or document library name….
….followed by the title (if a list item) or file name (if in a document library) of the item.
The output from the command will look similar to the screenshot below:
As the script creates the table using the New-Object PSObject command, you can output it in a number of different ways and formats. For example, to output the table sorted by the “Display Name” column, type the following command:
Get-SPItemValues | Sort-Object -Property "Display Name"
To output the table contents to a CSV file, type the following command:
Get-SPItemValues | Sort-Object -Property "Display Name" | Export-Csv -NoType -Path c:\columnvalues.csv
To output the table contents to a grid view, where the output is displayed in an interactive table (requires Microsoft .NET Framework 3.5 with Service Pack 1), type the following command:
Get-SPItemValues | Sort-Object -Property "Display Name" | Out-GridView
Below is a screenshot showing how the grid view looks when using Windows PowerShell ISE: