Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add Site Columns using Powershell
WhatsApp
Venkata Appaji
Jun 22
2016
1.7
k
0
0
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"
Powershell
Site Columns
Up Next
Add Site Columns using Powershell