Getting Airports and Weather Info near You

by Dec 1, 2015

PowerShell can talk to web services, and there are some public web services that you can contact via internet. Here are two functions: Get-Airport gets all supported airports in a given country. Get-Weather then gets the current weather information:

#requires -Version 2

function Get-Airport
{
    param($Country, $City='*')

    $webservice = New-WebServiceProxy -Uri 'http://www.webservicex.net/globalweather.asmx?WSDL' 
    $data = [xml]$webservice.GetCitiesByCountry($Country)
    $data.NewDataSet.Table |
      Where-Object { $_.City -like "*$City*" }

}

function Get-Weather
{
    param($City, $Country='Germany')

    $webservice = New-WebServiceProxy -Uri 'http://www.webservicex.net/globalweather.asmx?WSDL'
    $data = [xml]$webservice.GetWeather($City, $Country)
    $data.CurrentWeather
}

Use it like this:

 
PS> Get-Airport -Country Bahamas

Country                                        City                                          
-------                                        ----                                          
Bahamas                                        Alice Town, Bimini                            
Bahamas                                        Georgetown, Exuma                             
Bahamas                                        Freeport, Grand Bahama                        
Bahamas                                        West End, Grand Bahama                        
Bahamas                                        Matthew Town, Inagua                          
Bahamas                                        Nassau Airport                                
Bahamas                                        Cockburn Town, San Salvador                   



PS> Get-Weather -Country Bahamas -City 'Freeport, Grand Bahama'


Location         : Freeport, Grand Bahama, Bahamas, The (MYGF) 26-33N 078-42W 11M
Time             : Oct 23, 2015 - 11:00 AM EDT / 2015.10.23 1500 UTC
Wind             :  from the ENE (070 degrees) at 17 MPH (15 KT):0
Visibility       :  greater than 7 mile(s):0
SkyConditions    :  partly cloudy
Temperature      :  80 F (27 C)
DewPoint         :  71 F (22 C)
RelativeHumidity :  74%
Pressure         :  30.03 in. Hg (1016 hPa)
Status           : Success
 

Twitter This Tip! ReTweet this Tip!