In this part of this mini-series, we are showing you how Invoke-WebRequest can download files from the internet for you. Simply use the parameter -OutFile. This code downloads a PowerShell icon as PNG image onto your desktop:

$url = "http://www.dotnet-lexikon.de/grafik/Lexikon/Windowspowershell.png"
$destination = "$home\powershell.png"

Invoke-WebRequest -Uri $url -OutFile $destination -UseBasicParsing
Invoke-Item -Path $destination

Note that Invoke-WebRequest can only download files hosted on HTTP addresses. Trying to download from an HTTPS address raises an error. Check out our next tip to work around this!

Twitter This Tip! ReTweet this Tip!

Anonymous