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.
Download files from the Internet using PowerShell.
November 14, 2016
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
You May Also Like