Tuesday, March 8, 2011

Powershell script - Get all Site Columns for a SharePoint 2010 site collection

Here is the powershell script to retrieve all Site Columns for a SharePoint 2010 site collection and output the details into a .csv file

Copy the code below and change the Site Collection URL and Output Path as per your requirement, save the following as .ps1 file:

Add-PsSnapin Microsoft.SharePoint.PowerShell
## SharePoint DLL
# Description
#   Output all available Column Field GUIDs to AllColumnFields.csv

# Settings Start
set-variable -option constant -name url     -value "http://localhost"       # Site collection
set-variable -option constant -name out     -value "C:AllColumnFields.csv"           # Output file
# Settings End

$site   =    new-object Microsoft.SharePoint.SPSite($url)
$web    = $site.rootweb.Fields
echo "Generating File..."
ForEach ($id in $web)
'"' + $id.Title + `
'","' + $id.Id + `
'","' + $id.InternalName + `
'","' + $id.StaticName + `
'","' + $id.MaxLength + `
'","' + $id.Description + `
'","' + $id.Group + `
'","' + $id.TypeShortDescription + `
'"' | Out-File $out -append
echo "Finished"
echo "File created at : " $out

Remove-PsSnapin Microsoft.SharePoint.PowerShell

It outputs all the Site Column details available in the Site Columns Gallery to a .csv file.


  1. Good article. But I just want to download site columns that in my dept group. whre group name = HRContentType

  2. Looks good, but when I run the script substituting my own variables I get this for $url and $out:
    Set-Variable : Cannot overwrite variable out because it is read-only or constant.

    What am I missing?

  3. Hi,

    I read ur blog and need iinformation on something which i am trying to do. I have managed metadata column( mapped to termstore). I want to tag my web pages using powershell with one of values of term store. I am not able to do so. Then i though i will set default value in site column page through powershell. I am not able to acheive that also. Can you please guide me in any one of these implementations. THanks

  4. Great Script.

    But can this works against SharePoint 2007 ?

    Many thanks.


  5. Thanks, was very helpful


  6. nice,

    This works in 2007 and 2010 and since powershell is .net it can easily be ported to functions in c# .net

  7. Thanks for the script. When I ran this I had to go back to the script to see what each column contained. I added one line right above the ForEach block to show titles in the first row of the file.

    'Title,ID,InternalName,StaticName,MaxLength,Description,Group,TypeShortDescription' | Out-File $Out -append

    I hope this helps others.


  8. Perfect, just what i have been looking for. Thanks! Jay