Downloads and saves a file in the current working directory of PowerShell.
Can you use the previous working directory ($pwd) or change it to a fixed location: “C:\Download” or by first change the directory in PowerShell.
Examples of changing the directory:
$storageDir = $pwd # or: $storageDir = "C:\Downloads" #or: cd C:\Users\Teusje\Documents $storageDir = $pwd
Below is the script to download a file via PowerShell. You can run it directly in PowerShell:
$storageDir = $pwd $webclient = New-Object System.Net.WebClient $url = "http://teusje.files.wordpress.com/2011/02/giraffe-header1.png" $file = "$storageDir\myNewFilename.jpg" $webclient.DownloadFile($url,$file)
Have fun!
Pingback: Downloading files with PowerShell using the BitsTransfer module | Teusje
Hi
great post thanks it helped me lots
I am using your code to download the latest WSUSScn2.CAB file
url = “http://go.microsoft.com/fwlink/?LinkId=76054″
@Romulo,
HAH me too! MBSA offline FTW!
Hey, how do i know that the file have been downloaded?
Thanks, exactly what I needed,
also have a look at invoke-webrequest in powershell v3:
http://teusje.wordpress.com/2012/12/29/web-scraping-with-powershell/