How to call a Web Service in PS

Simple as of PS v2.0 you can use the

New-WebServiceProxy object to get data from a Web Service API in just a few lines.

cls
$Weather = New-WebServiceProxy -Uri `
"http://www.webservicex.com/globalweather.asmx?WSDL"
$Weather.GetWeather("Antwerp","BE")

# Or this one, look at the Expand table option !
$zip = New-WebServiceProxy -Uri http://www.webservicex.net/uszip.asmx?WSDL 
$zip.GetInfoByCity('New York')|select -expand table|ft city, state, zip, area_code -auto

This is the XML output :

<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>   <Location>Antwerpen / Deurne, Belgium (EBAW) 51-12N 004-28E 14M</Location>   <Time>Jan 22, 2013 - 03:20 AM EST / 2013.01.22 0820 UTC</Time>   <Wind> from the E (090 degrees) at 3 MPH (3 KT):0</Wind>   <Visibility> less than 1 mile:0</Visibility>   <SkyConditions> mostly cloudy</SkyConditions>   <Temperature> 26 F (-3 C)</Temperature>   <DewPoint> 24 F (-4 C)</DewPoint>   <RelativeHumidity> 92%</RelativeHumidity>   <Pressure> 29.65 in. Hg (1004 hPa)</Pressure>   <Status>Success</Status>
</CurrentWeather>

Enjoy !

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: