Created
May 8, 2018 03:47
-
-
Save jamesbannan/73ffa90133d2bc66941952f52cfeb1e3 to your computer and use it in GitHub Desktop.
Find nearest Azure region based on IP address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all Azure regions accessible with my subscription | |
$regions = az account list-locations | ConvertFrom-Json | |
$locations = $regions | Select-Object displayName,latitude,longitude | Sort-Object displayName | |
# Get my location based on IP address | |
$request = (Invoke-WebRequest -Uri http://ip-api.com/json).Content | ConvertFrom-Json | |
$latitude = $request.lat | |
$longitude = $request.lon | |
$hash = [ordered]@{ | |
latitude="$latitude"; | |
longitude="$longitude"; | |
locations=@($locations) | |
} | |
$body = $hash | ConvertTo-Json -Depth 100 | |
# Get nearest Azure region | |
$uri = 'https://azureregion.azurewebsites.net/api/nearestRegionFromIp' | |
Invoke-RestMethod -Method Put -Uri $uri -Body $body |
Hi, I got this error message:
The remote name could not be resolved: 'azureregion.azurewebsites.net'
I'm running the script locally using PowerShell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this script you need PowerShell (not Azure PowerShell) and the Azure CLI.