8

I'm looking for a way to gather internal GPS data from a powershell script using Windows Location API, as the Windows Location Platform is no longer able to satisfy the need. Previously, there was a com object to use.

Is there a way for this to be accomplished in Windows 10?

jamcarro
  • 83
  • 1
  • 1
  • 3
  • more solutions [here](https://codegolf.stackexchange.com/questions/119078/err-where-am-i?newreg=983b00097ef141c6b1fbb7f29b357886#answer-119091). – eadmaster Jun 23 '19 at 21:24

2 Answers2

19

An example of using the System.Device.Location method, this should be what you're looking for.

Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object
$GeoWatcher.Start() #Begin resolving current locaton

while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied')) {
    Start-Sleep -Milliseconds 100 #Wait for discovery.
}  

if ($GeoWatcher.Permission -eq 'Denied'){
    Write-Error 'Access Denied for Location Information'
} else {
    $GeoWatcher.Position.Location | Select Latitude,Longitude #Select the relevent results.
}
colsw
  • 3,216
  • 1
  • 14
  • 28
0

Make sure location is set on. Ohterwise it outputs 'Access Denied for Location Information'

Louis
  • 3
  • 2
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 20 '21 at 23:19