Category filter

Script to fetch location coordinates on Windows devices

Fetching the location coordinates helps identify where a device is currently located. The latitude and longitude coordinates of a device are crucial in determining the precise locations of remote workforce. This helps the IT admins ensure that employees use company-owned devices from permitted locations. Using Hexnode’s Execute Custom Script action you can execute scripts to obtain the exact location coordinates of a Windows device.


The sample scripts provided below are adapted from third-party open-source sites.

PowerShell script

This script uses system.device.location(GeoCoordinateWatcher) method to get the location coordinates. Once the action succeeds, you can view the location coordinates by navigating to the Action History page of the device on which the script has been executed. Click on Show Output corresponding to the Execute Custom Script action that had been initiated to view the location coordinates.

Fetched location coordinates of a Windows device


  • This script works only if location is enabled on the device. To enable location settings, navigate to Start > Settings > Privacy (Privacy & Security in case of Windows 11) > Location and toggle on Location service/Location access.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository