PowerShell

SharePoint – Retrive the internal column name for lists/libraries using PowerShell

I have been using this method for some time now and decided to make a slight change to it.  I have been using the PowerShell method found here to find the internal column names for my lists and libraries.  It works great.  The only problem with this is that I have to modify the script each time I need to change the value of the list or site.  This is usually not a big deal since I generally am only looking at one list.  This was not the case the other day.  I needed to look at many different lists in the same site.  Instead of having to modify the script each time, I added a set of parameters to prompt me at the command line.  The code looks like this:

Param(
	[Parameter(Mandatory=$true,Position=1)]
	[string]$Site,
	[Parameter(Mandatory=$true,Position=2)]
	[string]$ListName
	)
###### Declare Input Parameters -- Includes Hidden Fields ############
$web = Get-SPWeb $Site;
$list = $web.Lists["$ListName"]

$list.fields | select Title, InternalName, Hidden, Sealed, CanBeDeleted | where {$_.Hidden -eq $false} | sort title | ft -AutoSize
  1. Download Get Column Names Script
  2. Save the script to a directory on your SharePoint server
  3. Open the SharePoint Management Shell for PowerShell
  4. Navigate to the directory where you downloaded the script
    example:  d:\scripts
  5. Run the script: getColumnName.ps1
  6. Enter in the variables
    ***To include hidden fields, change {$_Hidden -eq $false} to {$_Hidden -eq $true}***

Your screen should resemble the following before the command runs

psGetCN

Mike Smith has a lot of great tips on his site.  I suggest that you check it out:  http://techtrainingnotes.blogspot.com/

Stay Salty!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.