Download File with a PowerShell One-Liner
I was recently trying to automate some scripts on a linux box and I wanted to know if it was as simple to download a file in PowerShell as it is in linux: wget http://example.com/file.jpg
Well as it turned out, it wasn’t, but it wasn’t that difficult either. What we needed was too use the System.Net.WebClient class. There’s one thing to note, in PowerShell you can’t use a ~ (tilde) to reference your home directly, that is to say, you can’t download a file to ~\Desktop
you will need to specify the full path, in my case C:\Users\Brangle\Desktop
.
1 | (new-object System.Net.WebClient).Downloadfile("http://wordpress.org/latest.zip", "C:\Users\Brangle\Desktop\wp-latest.zip") |