Sunday 13 January 2019

Download files with Powershell.

Want to download files with Powershell?
Small files that need to be downloaded from internal repositories?
Additional portable tools , executable that are required for the scripts to do, we could grab them with these methods.

We could use the cmdlet
Method 1:
Invoke-WebRequest

$PuttyDownloadUrl =  "https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe"
$LocalDlPath =  "C:\runspace\Putty.exe"
Invoke-WebRequest -Uri $PuttyDownloadUrl -OutFile $LocalDlPath
test-path C:\runspace\Putty.exe










Method 2:
Using the .NET class System.Net.WebClient

$PuttyDownloadUrl =  "https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe"
$LocalDlPath =  "C:\runspace\Putty.exe"
$dlObject = New-Object System.Net.WebClient
$dlObject.DownloadFile($PuttyDownloadUrl, $LocalDlPath)
test-path C:\runspace\Putty.exe




Happy Scripting!!

No comments:

Post a Comment