Have you ever wanted to write a script that will get the weather forecast or maybe travel directions? Many sites expose web services that you can tap into from PowerShell to do things like converting currency, getting news headlines, or really anything! Maybe you already have created your own web service and simply want to consume it from PowerShell.
The first step is to create a Web Service Proxy to access the methods of the web service. This is done by using the New-WebServiceProxy cmdlet. When using this cmdlet point it to the url of your web service:
$zip = New-WebServiceProxy -Uri http://www.webservicex.net/uszip.asmx?WSDL
$zip | gm -MemberType method
Name
----
Abort
BeginGetInfoByAreaCode
BeginGetInfoByCity
BeginGetInfoByState
BeginGetInfoByZIP
CancelAsync
CreateObjRef
Discover
Dispose
EndGetInfoByAreaCode
EndGetInfoByCity
EndGetInfoByState
EndGetInfoByZIP
Equals
GetHashCode
GetInfoByAreaCode
GetInfoByAreaCodeAsync
GetInfoByCity
GetInfoByCityAsync
GetInfoByState
GetInfoByStateAsync
GetInfoByZIP
GetInfoByZIPAsync
GetLifetimeService
GetType
InitializeLifetimeService
ToString
$zip.GetInfoBYZip(43209).Table
CITY : Columbus
STATE : OH
ZIP : 43209
AREA_CODE : 614
TIME_ZONE : E
# Define an array of Zip Codes
[array] $zipAry = @(43209,90210,33614)
# Iterate each Zip code and get the City and State
foreach($zipCode in $zipAry)
{
$zip.GetInfoByZip($zipCode).Table | Select City,State | Format-list
}
CITY : Columbus
STATE : OH
CITY : Beverly Hills
STATE : CA
CITY : Tampa
STATE : FL
Google offers a Directions API Web Service that you can use for getting travel directions.