Steps:
- Start your windows PowerShell on your computer.
- Right click and select Run as administrator option.
- Paste the below script on the PowerShell window and click the enter button.
- Check your SharePoint site Feature will activated successfully.
- #Get site and web object
- $site = Get-SPSite -Identity "http://gauti.sharepoint.com"
- $web = $site.RootWeb
-
- #Assign fieldXML variable with XML string for site column
-
- $fieldXML = '<Field Type="DateTime"
- Name="DateColumn"
- Description="Site Column created by using Powershell with format of date column."
- DisplayName="Date Column"
- StaticName="DateColumn"
- Group="Test Site Columns"
- 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()
Run the script and check the sharepoint site column created successfully.