Add Geolocation column in SharePoint using PowerShell

Hello Friends, in this article we will learn  how to add Geolocation column in SharePoint. Using powershell, we can enable a Geo-location column on a custom list in SharePoint online. We will use a PowerShell script to add Geo-location column in our list. The same script can be used for SharePoint 2010/2013.

Add Geolocation column in SharePoint using PowerShell

  1. Open Windows PowerShell ISE

    Windows PowerShell ISE
    Windows PowerShell ISE
  2. Write below PowerShell code and run the same. Make the necessary changes in the below code like: $WebUrl, $EmailAddress, $List.
    #Load SharePoint CSOM Assemblies
    Add-Type -Path "C:\Users\Desktop\Data\Old\Microsoft.SharePoint.Client.Runtime.dll"
    Add-Type -Path "C:\Users\Desktop\Data\Old\Microsoft.SharePoint.Client.dll"
    
    #Define SharePoint URL, login details
    $WebUrl = 'https://myclassbook.sharepoint.com/teams/TestSite/'
    $EmailAddress = "[email protected]"
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
    $Credentials = Get-Credential -UserName $EmailAddress -Message "Please enter your Office 365 Password"
    $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($EmailAddress,$Credentials.Password)
    
    #Define list name where we need to add Geolocation column
    $List = $Context.Web.Lists.GetByTitle("Project Portals")
    $FieldXml = "<Field Type='Geolocation' DisplayName='Location'/>"
    $Option=[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView
    $List.Fields.AddFieldAsXml($fieldxml,$true,$option)
    $Context.Load($list)
    $Context.ExecuteQuery()
    $Context.Dispose()

    Screenshot of the above code:

    Add geolocation column in sharepoint using powershell
    Add Geo-location column in SharePoint using PowerShell
  3. Once the script is successfully executed, you can see that the Geolocation columns with Display Name “Location” will be added in your list.

    Add Geolocation column in SharePoint using PowerShell
    Add Geolocation column in SharePoint using PowerShell

Downloads:
1) Microsoft.SharePoint.Client.Runtime.dll
2) Microsoft.SharePoint.Client.dll
3) PowerShell Script

You may also like:

I hope you liked this article. Please let us know in case you are having any questions in the comment section below. Like our facebook page and subscribe to our newsletter for future updates. have a great time 🙂