Downloading Information from Internet (Part 6)

by Apr 20, 2018

In the previous tip we explained how you can retrieve XML data from webpages using either Invoke-WebRequest or Invoke-RestMethod. For XML data, there is also another approach which uses the built-in methods found in the XML object itself.

This was the approach with Invoke-RestMethod:

$url = ''
(Invoke-RestMethod -Uri $url -UseBasicParsing).Envelope.Cube.Cube.Cube

As an alternative, try this:

$url = ''
$xml = New-Object -TypeName XML

It is much faster; however, it does not provide you with the multitude of parameters available in Invoke-RestMethod to handle proxy servers and credentials.

Twitter This Tip! ReTweet this Tip!