Create a Site Column using Powershell in SharePoint

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.
  1. #Get site and web object  
  2. $site = Get-SPSite -Identity "http://gauti.sharepoint.com"  
  3. $web = $site.RootWeb  
  4.  
  5. #Assign fieldXML variable with XML string for site column  
  6.   
  7. $fieldXML = '<Field Type="DateTime"  
  8. Name="DateColumn"  
  9. Description="Site Column created by using Powershell with format of date column."  
  10. DisplayName="Date Column"  
  11. StaticName="DateColumn"  
  12. Group="Test Site Columns"  
  13. Hidden="FALSE"  
  14. Required="FALSE"  
  15. Sealed="FALSE"  
  16. ShowInDisplayForm="TRUE"  
  17. ShowInEditForm="TRUE"  
  18. ShowInListSettings="TRUE"  
  19. ShowInNewForm="TRUE"></Field>'  
  20.  
  21. #Output XML to console  
  22. write-host $fieldXML  
  23.  
  24. #Create site column from XML string  
  25. $web.Fields.AddFieldAsXml($fieldXML)  
  26.  
  27.  
  28. #Dispose of Web and Site objects  
  29. $web.Dispose() 
Run the script and check the sharepoint site column created successfully.