Reader Level:
ARTICLE

Add and Modify the existing site column in SharePoint 2010 using powershell

On February 17, 2011 Articles | SharePoint
In this article we will be seeing how to add a new custom site column and modify the existing site column in SharePoint using powershell scripts.
  • 0
  • 0
  • 23872

In this article we will be seeing how to add a new custom site column and modify the existing site column in SharePoint using powershell scripts.

Adding a new custom site column using powershell script

$site = Get-SPSite -Identity "http://serverName:4001/"
$web = $site.RootWeb

$fieldXML = '<Field Type="Text"
Name="CustomSiteColumn"
Description="This is a Custom Site Column."
DisplayName="Custom Site Column"
Group="Custom Site Column"
Hidden="FALSE"
Required="FALSE"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInListSettings="TRUE"
ShowInNewForm="TRUE"></Field>'

$web.Fields.AddFieldAsXml($fieldXML)
$web.Dispose()
$site.Dispose()


(OR)

$site = Get-SPSite -Identity "http://serverName:4001/"
$web = $site.RootWeb
$web.Fields.Add("CustomSiteColumn",[Microsoft.SharePoint.SPFieldType]::Text,$true)
$web.Dispose()
$site.Dispose()

A new custom site column is created successfully using the above script.

share1.gif

Modify the existing column property using powershell script

$site = Get-SPSite -Identity "http://serverName:4001/"
$web = $site.RootWeb
$field=$web.Fields["Custom Site Column"]
$field.Type= "Choice"
$field.Update($true)
$web.Dispose()
$site.Dispose()

The property of the existing site column is changed from "Text" to "Choice".

share2.gif

Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, S...

  • 3rank
  • 6M readers
  • 3times
COMMENT USING

Trending up