PoshTip #7 – How to retrieve a file from a given URL
You can use Invoke-WebRequest to download files.
First method
To simply download a file through HTTP, you can use this command
1 |
wget "http://technet.microsoft.com/" -OutFile "C:\out.html" |
wget is an alias for Invoke-WebRequest
1 |
Invoke-WebRequest -Uri "http://technet.microsoft.com" -OutFile "C:\out.html" |
If the web server requires authentication, you have to use the -Credential parameter
Second method
Use the .NET WebClient object
1 2 |
$WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("http://technet.microsoft.com/","C:\out.html") |