locked
Creating Site Columns via PowerShell RRS feed

  • Question

  • Hi all,

    Is it possible to create site columns for a site via PowerShell?  I haver about 50 columns I need to create and doing so via the GUI manually would take forever.

    Any pointers are welcome.


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
    Tuesday, November 1, 2011 10:40 AM
    Answerer

Answers

  • Ok nailed it.  Just used this basic script, which I'll customise for specific data types and groups as needed.

    Add-PSSnapIn "Microsoft.SharePoint.Powershell"
    #Get the site collection and web object
    $siteColl = Get-SPSite -Identity "http://engchesqltemp/"
    $rootWeb = $siteColl.RootWeb
    #Assign fieldXMLString variable with field XML for site column
    $fieldXMLString = '<Field Type="Text"
    Name="LocalServiceReview"
    Description="Indicate date of last and next meeting and names of current members."
    DisplayName="Local Service Review Team"
    StaticName="LocalServiceReview"
    Group="Portman Applications"
    Hidden="FALSE"
    Required="FALSE"
    Sealed="FALSE"
    ShowInDisplayForm="TRUE"
    ShowInEditForm="TRUE"
    ShowInListSettings="TRUE"
    ShowInNewForm="TRUE"></Field>'
    #See field XML on console
    write-host $fieldXMLString
    #Create site column from XML string
    $rootWeb.Fields.AddFieldAsXml($fieldXMLString) 
    



    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
    Tuesday, November 1, 2011 11:59 AM
    Answerer

All replies

  • Ok nailed it.  Just used this basic script, which I'll customise for specific data types and groups as needed.

    Add-PSSnapIn "Microsoft.SharePoint.Powershell"
    #Get the site collection and web object
    $siteColl = Get-SPSite -Identity "http://engchesqltemp/"
    $rootWeb = $siteColl.RootWeb
    #Assign fieldXMLString variable with field XML for site column
    $fieldXMLString = '<Field Type="Text"
    Name="LocalServiceReview"
    Description="Indicate date of last and next meeting and names of current members."
    DisplayName="Local Service Review Team"
    StaticName="LocalServiceReview"
    Group="Portman Applications"
    Hidden="FALSE"
    Required="FALSE"
    Sealed="FALSE"
    ShowInDisplayForm="TRUE"
    ShowInEditForm="TRUE"
    ShowInListSettings="TRUE"
    ShowInNewForm="TRUE"></Field>'
    #See field XML on console
    write-host $fieldXMLString
    #Create site column from XML string
    $rootWeb.Fields.AddFieldAsXml($fieldXMLString) 
    



    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
    Tuesday, November 1, 2011 11:59 AM
    Answerer
  • What if we don't want to create it at the RootWeb, but at a Web level? Can you show?
    Tuesday, September 20, 2016 9:04 PM