Calling web services from Powershell

This example will call a web service to get the weather.

First , create a reference to the web service.

$uri = “
$ws = New-WebServiceProxy -Uri $uri

To see what methods are available:

$ws | Get-Member -MemberType Method

To get the definition for the service:

($ws | Get-Member -Name GetCityWeatherByZIP).definition

To call the service to get all weather data for ZIP 30080 (Smyrna, GA):


Or to just display certain pieces of information:

$Weather = $ws.GetCityWeatherByZIP(“30080”)
Write-Host “City: “$Weather.City.ToString()
Write-Host “Description: “$Weather.Description.ToString()
Write-Host “Temperature: “$Weather.Temperature.ToString()


Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: