2017-09-18 165 views

回答

2

使用System.Device.Location方法的一個例子,這應該是你正在尋找的。

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. 
}