Invoke-WebRequest

Powershell 3.0 introduced Invoke-WebRequest cmdlet which offers a lot of options regarding HTTP requests. Rather then repeating the documentation and other sources, I’m going to show a simple example – the script below finds some specific links in the given web page and download them. It uses Invoke-WebRequest for both getting (and parsing) the web page and downloading files.

$url = 'http://blogs.msdn.com/b/briankel/archive/2011/09/16/visual-studio-11-application-lifecycle-management-virtual-machine-and-hands-on-labs-demo-scripts.aspx'
cd c:\temp\
 
$site = Invoke-WebRequest -Uri $url
$links = $site.Links | where href -like "http://download.microsoft.com*" | select -expand href
$links | % { Invoke-WebRequest -Uri $_ -OutFile (Split-Path $_ -Leaf) }

Leave a Reply

Your email address will not be published.