Thursday, May 14, 2015

wget equivalent in PowerShell

As some have pointed out there is not the equivalent for wget in PowerShell 1 or 2. It is included as Invoke-WebRequest in PowerShell 3.

To implement it yourself in PowerShell 1 or 2, you can use the following:

## Declare a function that takes source and destination arguments
Function Get-Webclient ($url, $out) {
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$request = New-Object System.Net.WebCLient
$request.UseDefaultCredentials = $true ## Proxy credentials only
$request.Proxy.Credentials = $request.Credentials
$request.DownloadFile($url, $out)

## Call the function with our source and destination.
Get-Webclient "" "C:\Foo3.txt"

Credit to this post.

1 comment:

fanny said...

Far and away the best prize that life offers is the chance to work hard at work worth doing.
This is football game,you can try to play for free:Cheap FIFA 16 Coins and FIFA 16 Coins