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
0 comments
Hide comments