Fun: Get Weather information in PowerShell


Found these helpful sites (http://ipinfo.io and http://wttr.in and wrote an script to get and display weather information of your current location. Now in a shell, I can check weather information too. 🙂

<#
 Script: Get-Weather.ps1
 Description: This script will
     * Get current location
     * Find the Weather info
     * Display the weather info

 Fun fact: This command will display the GPS location
 information

 Invoke-RestMethod -URI "ipinfo.io" -Method GET | Select  City,Region,Country,loc | FT -auto

#>

#Get current location (city)
$City = (Invoke-RestMethod -URI "ipinfo.io" -Method GET).City

#get Weather info
$weather = Invoke-WebRequest -Uri "http://wttr.in/$City"
$WeatherInfo = $weather.ParsedHtml.body.outerText

#Display the weather info
$WeatherInfo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s