Download a file from the Internet using PowerShell

Download files from the Internet using PowerShell.

John Savill

November 14, 2016

1 Min Read
Download a file from the Internet using PowerShell

Q. How can I download a file using PowerShell from the Internet?

A. Using the Invoke-WebRequest it's possible to download content from a web location and save to a local file. Below is an example downloading a file from my site however you could change to download anything:

$folder = "d:temp"$url= "http://www.savilltech.com/images/MasterClassLogoMedium.png"$req = [System.Net.HttpWebRequest]::Create($url)$req.Method = "HEAD"$response = $req.GetResponse()$fUri = $response.ResponseUri$filename = [System.IO.Path]::GetFileName($fUri.LocalPath); $response.Close()$target = join-path $folder $filename Invoke-WebRequest -Uri $url -OutFile $target 

 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like