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"

  14. With havin so much written content do you ever run into any problems of plagorism or copyright violation?
    My site has a lot of unique content I’ve either authored myself or outsourced but it seems a lot of it is….
    popping it up all over the internet without my agreement.
    Do you know any solutions to help prevent content from being ripped off?

  15. I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.

  16. Thanks for sharing superb informations. Your web-site is very cool. I am impressed by the details that you have on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched everywhere and simply could not come across. What a great web-site.

  17. Nice stuff, but don't you need an ID field ?

  18. After I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment
    is added I recieve 4 emails with the same comment. There has to be an easy method you can remove me from that service?
    Thank you!

  19. Hi! Do you know if they make any plugins to assist with
    Search Engine Optimization? I’m trying to get my blog to rank for some
    targeted keywords but I’m not seeing very good results.
    If you know of any please share. Thanks!

  20. is a online divorce resource for divorce attorney, attornies and lawyers. You will find the best divorce information online. Divorce Mind will make your divorce or separation a quick, convenient and private....