Saturday, 26 June 2010

Create a new SharePoint site column using PowerShell

The script below can be used to create a new site column. It assumes you are creating the column in the top-level site of a site collection. It can be used to create columns in a Content Type Hub site, which can then be propagated to other site collections in the farm using the Managed Metadata Service Application (a story for another blog article maybe).

The main advantages of using PowerShell to create the site column are that you can document the changes, easily repeat them across development, staging and production environments, and you can set some properties that are not available to select in the UI (e.g., the “ShowIn” properties at the end of the XML string).

#Assumes that you are creating the site column in the top-level site of a site collection
#Script can also be used to create a site column in the Content Type Hub

#Get site and web object
$site = Get-SPSite -Identity "http://portal"
$web = $site.RootWeb

#Assign fieldXML variable with XML string for site column
$fieldXML = '<Field Type="DateTime"
Description="This is a test date column."
DisplayName="Test Date"
Group="Test Custom Columns"

#Output XML to console
write-host $fieldXML

#Create site column from XML string

#Example of changing the site column settings after creation
#Configure Test Date column to be Date Only instead of Date & Time
$dtField = $web.Fields["Test Date"]
$dtField.DisplayFormat = "DateOnly"

#Dispose of Web and Site objects

Note at the end of the script that I call the new column back so that I can change a setting. You could add column settings to the XML during creation, but changing it after creation can be useful if you have already created the column and wanted to make further changes.


  1. This came in handy in my situation

    In the change settings:

    $dtField.PushChangesToLists = "TRUE"

  2. Hi. I used your script to create my site column. I mistyped my field type as 'choice' instead of 'Choice' and that corrupted my site columns page under site settings. Is there any way I can delete my site column again using a powershell script? I can't delete via UI or SharePoint Designer. Thanks.

  3. Try this:


  4. Or this if it is a site column:


  5. Hi Phil

    I have the same question as Anonymous above.
    A typo caused my site settings column page to error. I created a custom column but haven't used it in any content type, workflow or list yet. How can I delete it from my site columns?

    Thanks in advance!

  6. Hi - Use the UI to delete the column or following the links I posted above

  7. I can't access the UI pages, so can't delete them over there.
    The links show an example of deleting a column from a specific content type or list, which I don't have.

    Could I do something like this:

    $web = Get-SPWeb http://portal
    $spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($web.Fields["MyCustomField"])


  8. Try this:

    $web = Get-SPWeb http://portal
    $column = $web.Fields["Bad Column"]

  9. I'm getting a null value.
    Investigating why, I'll let you know if I find the problem.

    Thanks for your feedback.

  10. how this site column created can be referenced to a list using powershell

  11. Use SharePoint Manager 2010?

  12. Thanks! I am working on a script to read parameters from a file and build a set of site columns. Your script is very helpful. - Doug

  13. hi , I have a custom site column called 'reviewed' and this field type is 'checkbox'. we are referring this field in 30 contenttypes. these cotent types associated to 10 document libraries. now i want to change this field type to
    choice - dropdown , with required field option.

    how can i change 'type' of existing site column using powershell ?

    i tried to use below powershell luck

    $field =$RootWeb.fields.getfield("test1")
    $field.Type= "Choice"