ARTICLE

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

Posted by Vijai Anand Articles | SharePoint 2010 February 17, 2011
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.
Reader Level:

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

Login to add your contents and source code to this article
post comment
     

Thank you Sapna:-)

Posted by Vijai Anand Feb 17, 2011

Very nice article...

Posted by Sapna Feb 17, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.