Query openweathermap data with PowerShell
In order to run, the
variable $openweathermapAPIkey
must be set to a valid API key.
The script is invoked with latitude, longitude, for example like so:
PS C:\> openweathermap.ps1 47.509 8.6431
param (
[float] $lat,
[float] $lon
);
set-strictMode -version 3
$url = "https://api.openweathermap.org/data/2.5/weather?appid=$openweathermapAPIkey&lat=$lat&lon=$lon"
$res = convertFrom-json ((invoke-webRequest $url).content)
"Name: $($res.name)"
"Weather: $($res.weather.main) / $($res.weather.description)"
"Temperature: $($res.main.temp - 271.15), feels like $($res.main.feels_like - 271.15) (min/max: $($res.main.temp_min - 271.15)/$($res.main.temp_max - 271.15)"
"Pressure: $($res.main.pressure)"
"Humidity: $($res.main.Humidity)"
"Visibility: $($res.Visibility)"
"Wind: $($res.wind.speed) @ $($res.wind.deg)"
"Rain: $($res.rain.'1h')"
"Clouds: $($res.clouds.'all')"