Skip to content

Instantly share code, notes, and snippets.

@ady28
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ady28/b63b779aa4aa0e14603d to your computer and use it in GitHub Desktop.
Save ady28/b63b779aa4aa0e14603d to your computer and use it in GitHub Desktop.
#One liner in which I use Invoke-Restmethod and select only the 4 properties keeping the output as an object for other operations
Invoke-RestMethod -Uri "www.telize.com/geoip" | Select-Object -Property longitude,latitude,continent_code,timezone
#Advanced function that just calls the above CmdLet
Function GetGeoInformation
{
Invoke-RestMethod -Uri "www.telize.com/geoip"
}
#Use the dvanced function by placing the results in a variable
$geoinfo=GetGeoInformation | Select-Object -Property longitude,latitude,continent_code,timezone
<#
Another interesting service that has an XML endpoint is found at http://openweathermap.org/current. This site give you information about weather.
This page has infomation about using the service. I chose to use the longitude and latitude to retreive the weather data.
The url is: api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}
The bove function can be used for this:
#>
$geoinfo=GetGeoInformation
Invoke-RestMethod -Uri "api.openweathermap.org/data/2.5/weather?lat=$($geoinfo.latitude)&lon=$($geoinfo.longitude)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment