Thursday, 17 July 2014

Create Column using GUID by Powershell script

Steps:

1. Copy the Below script on notepad and save it to your preffered Location.

#Get the site collection and web object
$siteColl = Get-SPSite -Identity "Site Collection URL"
$rootWeb = $siteColl.RootWeb
#Assign fieldXMLString variable with field XML for site column
$fieldXMLString = '<Field Type="Text"
Name="Test_column"
ID="GUID"
Description="Indicate date of last and next meeting and names of current members."
DisplayName="Test1 Team"
StaticName="Test1"
Group="Base Column"
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)

2. Add the detail which is highlighted in red. (Site Collection URL, Column Name, Unique GUID, Display Name, Static Name and Group Name)

3. Now Run the script and check the column whether it is created or not.

4. To check Go to Top Level Site--> Site Action --->Site Settings-->Site Columns

5. You can find the newly created column in Site column.

Note: If you get the error please check the GUID use is Unique or not. If not please try with the Different GUID.

No comments:

Post a Comment