Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Last active September 25, 2017 14:17
Show Gist options
  • Save steviecoaster/47b89a220979f4be0243806ef3a30749 to your computer and use it in GitHub Desktop.
Save steviecoaster/47b89a220979f4be0243806ef3a30749 to your computer and use it in GitHub Desktop.
Current Weather in PS Profile
Function Get-CurrentWeather {
#Save this function inside your Powershell Profile. Not sure what that is? Just type in $profile and hit enter in your PS Console!
#File doesn't exist? That's OK, use Powershell to create it!
#New-Item -File -Path $env:USERPROFILE\Documents\WindowsPowershell\ -Value $profile
#Give your script a voice!
Add-Type -assemblyname System.Speech
$speech = New-Object System.Speech.Synthesis.SpeechSynthesizer
# The devil's in the details. You'll need an API key and to know your CityID, though Zip code will work with a modified URL.
$key = "YourAPIKeyHere" #API Key's are free from openweathermap.org
#Pulled from the master city ID json file. Download here: http://bulk.openweathermap.org/sample/city.list.json.gz
$cityid = "YourHomeTown"
$weather = Invoke-RestMethod -Uri "http://api.openweathermap.org/data/2.5/weather?id=$cityid&APPID=$key&units=imperial"
#You can comment out the next 2 lines if you don't want your prompt to talk to you.
$speech.Speak("Today's high will be $($weather.main.temp_max) degrees Fahrenheit. The Low, $($weather.main.temp_min) degrees Fahrenheit.")
$speech.Speak("It is currently $($weather.main.temp) degrees Fahrenheit")
Write-Host "Today's High: $($weather.main.temp_max) °F"
Write-Host "Today's Low: $($weather.main.temp_min) °F"
Write-Host "Current Temperature: $($weather.main.temp) °F"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment