Step 1: Preparing the .CSV file having all the site columns and values for their respective properties which we want to set.
For example the below .CSV file which we are using in this script,

Figure 1: Site Columns CSV file format
In the above .CSV file, column headings are basically the properties of the site columns. We can add any property as the column which we want to set. Each row represents the site column and their properties values.
Step 2:
Set the required variables like SiteCollection URL where we need to create the site columns,the UserName and Password of your site to connect a below:
- #Site collection URL where we need to create the site columns
- $siteurl = "" # Your site collection URL
- #User name and Passwords
- $userName ="" # Your user name
- $password ="" # Password
- #client context object and setting the credentials
- [Microsoft.SharePoint.Client.ClientContext]$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
- # convert password into secured string
- $securedpw = ConvertTo-SecureString $password -AsPlainText -Force
- $clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securedpw)
- #get the respective web
- $site = $clientContext.Site
- $web = $site.RootWeb
- #Get all fields collection
- $fields = $web.Fields
- $clientContext.Load($web)
- $clientContext.Load($fields)
- $clientContext.ExecuteQuery()
- # Import the site columns CSV file
- $fieldslist = Import-Csv -path 'C:\CreateSiteColumns.csv' #give here your .csv file path
- #Create the respective fields
- ForEach($field in $fieldslist)
- {
- #Prepare the fieldxml
- for Site Column - Please be careful with single and double quotes,
- if those got disturbed then it take some time to fix: )
- $fieldXML = "<Field Name='" + $field.Name + "' Type='" + $field.Type + "' Description='" + $field.Description + "' DisplayName='" + $field.DisplayName + "' StaticName='" + $field.StaticName + "' Group='" + $field.Group + "' Hidden='" + $field.Hidden + "' Required='" + $row.Required + "' Sealed='" + $field.Sealed + "' ShowInDisplayForm='" + $field.ShowInDisplayForm + "' ShowInEditForm='" + $field.ShowInEditForm + "' ShowInNewForm='" + $field.ShowInNewForm + "'></Field>"
- #reate Site Column from fieldXML
- $fields.AddFieldAsXml($fieldXML, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
- $clientContext.Load($fields)
- }
- #foreach
- $clientContext.ExecuteQuery()

Prasham SabadraPosted Aug 2, 2016, 2:08 AM
Ok. But if columns are created successfully this means no issue in connection. Is it possible to share the snap of error so that I can take a look once. Thanks!
Gurdeep KaurPosted Aug 1, 2016, 6:16 AM
Actually the columns are getting created but still I am getting the error "Unable to connect to remote server"
Prasham SabadraPosted Aug 1, 2016, 4:26 AM
Hi Gurdeep, please make sure you are putting correct details below. You are putting right user name and password. Also before executing the script just try to connect the office 365 using powershell. If possible then share the snap of error. $siteurl = "" # Your site collection URL #User name and Passwords $userName ="" # Your user name $password ="" # Password
Gurdeep KaurPosted Aug 1, 2016, 4:00 AM
Every time I execute the script I get the message as Unable to connect to the remote server
Prashant VermaPosted Mar 9, 2016, 10:13 AM
nice
Prasham SabadraPosted Feb 23, 2016, 8:40 AM
Thanks :)
Shriram PophaliPosted Feb 23, 2016, 5:32 AM
Nice article Prasham! Thanks