Creating Site Columns via PowerShell
Hi all, Is it possible to create site columns for a site via PowerShell? I haver about 50 columns I need to create and doing so via the GUI manually would take forever. Any pointers are welcome.Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
November 1st, 2011 6:44am

Ok nailed it. Just used this basic script, which I'll customise for specific data types and groups as needed. Add-PSSnapIn "Microsoft.SharePoint.Powershell" #Get the site collection and web object $siteColl = Get-SPSite -Identity "http://engchesqltemp/" $rootWeb = $siteColl.RootWeb #Assign fieldXMLString variable with field XML for site column $fieldXMLString = '<Field Type="Text" Name="LocalServiceReview" Description="Indicate date of last and next meeting and names of current members." DisplayName="Local Service Review Team" StaticName="LocalServiceReview" Group="Portman Applications" Hidden="FALSE" Required="FALSE" Sealed="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE"></Field>' #See field XML on console write-host $fieldXMLString #Create site column from XML string $rootWeb.Fields.AddFieldAsXml($fieldXMLString) Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
November 1st, 2011 8:00am

Ok nailed it. Just used this basic script, which I'll customise for specific data types and groups as needed. Add-PSSnapIn "Microsoft.SharePoint.Powershell" #Get the site collection and web object $siteColl = Get-SPSite -Identity "http://engchesqltemp/" $rootWeb = $siteColl.RootWeb #Assign fieldXMLString variable with field XML for site column $fieldXMLString = '<Field Type="Text" Name="LocalServiceReview" Description="Indicate date of last and next meeting and names of current members." DisplayName="Local Service Review Team" StaticName="LocalServiceReview" Group="Portman Applications" Hidden="FALSE" Required="FALSE" Sealed="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE"></Field>' #See field XML on console write-host $fieldXMLString #Create site column from XML string $rootWeb.Fields.AddFieldAsXml($fieldXMLString) Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
November 1st, 2011 2:59pm

Ok nailed it. Just used this basic script, which I'll customise for specific data types and groups as needed. Add-PSSnapIn "Microsoft.SharePoint.Powershell" #Get the site collection and web object $siteColl = Get-SPSite -Identity "http://engchesqltemp/" $rootWeb = $siteColl.RootWeb #Assign fieldXMLString variable with field XML for site column $fieldXMLString = '<Field Type="Text" Name="LocalServiceReview" Description="Indicate date of last and next meeting and names of current members." DisplayName="Local Service Review Team" StaticName="LocalServiceReview" Group="Portman Applications" Hidden="FALSE" Required="FALSE" Sealed="FALSE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInListSettings="TRUE" ShowInNewForm="TRUE"></Field>' #See field XML on console write-host $fieldXMLString #Create site column from XML string $rootWeb.Fields.AddFieldAsXml($fieldXMLString) Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
November 1st, 2011 2:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics