Quick Weather
A script a co-worker wrote to grab weather
$url = "http://w1.weather.gov/xml/current_obs/KSBN.xml" $data = Invoke-RestMethod $url $temp = $data.current_observation.temp_f -as [decimal] $wind = $data.current_observation.wind_mph -as [decimal] $weather = $data.current_observation.weather $temp_desc = $null $wind_desc = $null switch($temp) { { $_ -le 15 } { $temp_desc = "stupidly cold outside" } { $_ -le 40 -and $_ -gt 15 } {$temp_desc = "cold outside"} { $_ -le 60 -and $_ -gt 40 } {$temp_desc = "a little chilly outside"} { $_ -le 80 -and $_ -gt 60 } {$temp_desc = "warm and comfortable outside"} { $_ -le 90 -and $_ -gt 80 } {$temp_desc = "quite warm outside"} { $_ -le 100 -and $_ -gt 90 } {$temp_desc = "hot outside"} { $_ -gt 100 } {$temp_desc = "stupidly hot outside"} } switch($wind) { { $_ -le 0 } {$wind_desc = "quiet, a little too quiet...."} { $_ -le 5 -and $_ -gt 0 } {$wind_desc = "a gental breeze."} { $_ -le 10 -and $_ -gt 5 } {$wind_desc = "a brisk draft."} { $_ -le 15 -and $_ -gt 10 } {$wind_desc = "quite a bit windy."} { $_ -le 20 -and $_ -gt 15 } {$wind_desc = "blowing more than you would like."} { $_ -le 25 -and $_ -gt 20 } {$wind_desc = "frustratingly powerful."} { $_ -ge 26 } {$wind_desc = "an unstopable hurricane!"} } "The weather is currently $temp_desc with winds that are $wind_desc You might also notice it's $weather."
Save the script and then execute it like this:
./Get-QuickWeather.ps1
Another one-line example:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic –AllowRedirection