Extracting data from a web service

In this recipe, we will extract data from a free, public web service.

How to do it...

Let's explore how to access and retrieve data from a web service:

  1. Open PowerShell ISE as an administrator.
  2. Add the following script and run it:
    #delayed stock quote URI
    $stockUri = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx"
    
    $stockproxy = New-WebServiceProxy -Uri $stockUri -UseDefaultCredential 
    
    #get quote
    $stockresult = $stockProxy.GetQuote("MSFT","")
    
    #display results
    $stockresult.StockSymbol
    $stockresult.DayHigh
    $stockresult.DayLow
    $stockresult.LastTradeDateTime

How it works...

To work with a web service, we first need to create a proxy object that will allow us to access the methods available in a web service. ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.