Get GeoLocation with PowerShell and set NTP Server in a GPO

Using Powershell to locate your Geographical Location with the help of GeoLocation (IP-Address) is quite easy, cool and useful!

When we build Private and Hybrid Clouds across the globe in various countries and continents I want to make sure the Active Directory PDC Emulator is using a valid time source based on that location.

GeoLocation with Powershell

So with this small script (it’s using multiple WebServices to cycle through until it gets an answer) we can get a rough location for where we are and in my case it’s usually enough to know what country the datacenter is in.

That can then be used as you see fit. Though for me, I’m using it to update the Group Policy being applied to the PDC Emulator to point to the country specific NTP Pool with the generic pool as backup value.

That’s how easy it’s to modify a Group Policy object.

Please share any solutions using GeoLocation in the comments. It might give me some nice new ideas too!

 

8 thoughts on “Get GeoLocation with PowerShell and set NTP Server in a GPO”

  1. Snyggt. Hur kan jag formatera svaret från freegeoip så att ÅÄÖ visas korrekt? (I mitt fall får jag Jönköping som RegionName.)

  2. Om du använder denna istället för geoip i scriptet så ser den ut att hantera åäö. MEN den adressen du gav pekar på Timrå, så den databasen kanske inte är helt korrekt?
    Invoke-RestMethod -Method Get -Uri “http://ip-api.com/json/193.12.142.105”

Leave a Reply