Calling a SOAP web service from PowerShell 3.0

The other day, I wrote a longer blog post on some of the highlights of PowerShell. In there, I included an example of how to call a RESTful web service and how to make a HTTP call to an RSS feed.

Another common scenario might be that you want to get data from a SOAP-based web service. From the PowerShell 3.0 Step-By-Step book, they use in several places to showcase this. That is a website which has some free web services which you can use for testing.

So, how do you call a web service? Well, you need to create a proxy, then make the call (letting PowerShell know that the response will be XML), and then walk through or display the results. For example:

$proxy = New-WebServiceProxy -Uri
[xml]$response = $proxy.GetWeather("Tampa", "United States")
$response.CurrentWeather | Format-List

.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

This results in something like this:


What’s even cooler is that if I write this code in ISE, I get intellisense for what the data structure looks like:


So, I can dump the results out on the screen like we did above, or I also have direct access to each one of the properties which were returned.

It’s pretty cool I can do this with exactly 3 lines of code – very simple! For anyone not familiar with PowerShell, this isn’t some part of a bigger program. What I mean is, you can launch PowerShell on your computer right now, paste in those 3 lines of code – with nothing else – and you should see the same response on your own computer. Pretty cool stuff…

Posted in PowerShell, Uncategorized, Web Services
11 comments on “Calling a SOAP web service from PowerShell 3.0
  1. Neeraj_Pandey says:

    Hi Robert ,
    Need your suggestions for the following scenario-
    My network allows internet access through web proxy server. While writing script to make SOAP calls to a server which is in internet i have to specify URL,Port and credentials of web proxy server, and the application I am making SOAP calls to requires https authentication.
    Need your suggestions to specify both credentials (web proxy server and application ) in the script.
    Thanks and regards.


  2. Matt Murphy says:

    Hi Neeraj_Pandey,

    You can use these one of these two switches after creating the proxy object -UseDefaultCredential or -Credential

    UseDefaultCredential will attempt to pass your currently logged in Windows domain user to the site. The other switch allows you to specify credentials.

    if you need HTTPS then change the protocol in the URI string to https. SOAP allows RPC to traverse a firewall so normally uses port 80, but if you use HTTPS then it will use port 443.

    For example:
    $proxy = New-WebServiceProxy -Uri -UseDefaultCredential


  3. Shubham Garg says:

    I have a web service for which wsdl is not in pord environemnt exposed. how can i call that service. i tried by creating a wsdl file from qa but it takes qa xsd’s. please suggest it is critical


    • Robert Seder says:

      I don’t know of a way you can. This is part of the the security of SOAP services, that you MUST know the interface and data structures in order to use the service. If you don’t, I don’t know of any way around that. Sorry!


  4. Shubham Garg says:

    I did below and it worked :
    1. Created proxy from qa .
    2. Create a class library project and added the proxy class there.
    3. COnsumed the above created dll in powershell .


  5. Jorge Rial says:

    Hi Robert,

    I’m new in these matters and I need to call a SOAP WebService, that service search certain parameters, I need to pass these parameters but the the service that you are using doesn`t accept input parameters, how you specify the parameters? which service in Powershell should I use?

    I neew to execute something like the following code:



    I use the ISE as you recommend, but I don’t know how to proceed, any advice will be welcome.

    Thank you


  6. Matt Murphy says:

    I use WCFStorm to expose methods exposed by SOAP. You can download a trail copy from here (

    Tbh, the PowerShell IDE should expose the methods that are available like Robert described in his post. I would recommend recreating Robert’s example in the post to prove that you have the IDE setup correctly and then test with your SOAP API to see if it exposes the methods.


  7. […] Calling a SOAP web service from PowerShell 3.0 […]


  8. […] Source: Calling a SOAP web service from PowerShell 3.0 | Rob Seder […]


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

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: