Discover New "Internet"-Cmdlets in PowerShell 3.0

by May 13, 2013

With Invoke-WebRequest and Invoke-RestMethod, PowerShell 3.0 now has powerful support for downloading information from the Internet as well as communicating with Internet services. We have had a number of tips on these in the past.

Some people use Invoke-WebRequest to easily read RSS information. For example, this line is supposed to get the contents of the PowerShell team blog RSS feed:

$rss = ''

Invoke-RestMethod $rss |
  Select-Object -Property Title, Link, PubDate

As it turns out, this works, but the results are only partial. To get the complete team blog, you would have to use Invoke-WebRequest like this:

$rss = ''

$webpage = Invoke-WebRequest $rss
$xml = [XML]$webpage.Content
$ | Select-Object -Property Title, Link, PubDate

So to use these cmdlets, you need to play with them and find out how they work. Invoke-WebRequest always retrieves the complete content from a web page, but leaves it to you to pick the data and data type you need.

Twitter This Tip! ReTweet this Tip!