TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Add Site Columns using Powershell
Venkata Appaji
Jun 22
2016
Code
1.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Add - PSSnapin
"Microsoft.SharePoint.PowerShell"
#
Get site and web
object
$site = Get - SPSite - Identity
"http://siteurl"
$web = $site.RootWeb
function CreateSiteColumn($ColName, $DisplayName, $DataType) {#
Assign fieldXML variable with XML
string
for
site column
$fieldXML = @ " <
Field Type =
"$DataType"
Name =
"$ColName"
Description =
"Site Column created by using Powershell with format of $DataType column."
DisplayName =
"$DisplayName"
StaticName =
"$colName"
Group =
"Calpine"
Hidden =
"FALSE"
Required =
"FALSE"
Sealed =
"FALSE"
ShowInDisplayForm =
"TRUE"
ShowInEditForm =
"TRUE"
ShowInListSettings =
"TRUE"
ShowInNewForm =
"TRUE"
> < /Field>
"@#
Output XML to console
write - host $fieldXML# Create site column from XML
string
$web.Fields.AddFieldAsXml($fieldXML)# Dispose of Web and Site objects
$web.Dispose()
}
CreateSiteColumn
"MultiLineText"
"Multi Lines Text"
"Note"
CreateSiteColumn
"DateTime"
"Date Time"
"DateTime"
CreateSiteColumn
"SingleLineText"
"Single line of Text"
"Text"
CreateSiteColumn
"YesNo"
"Yes NO"
"Boolean"
Site Columns
Powershell