Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wget in PowerShell console with username and password

I have seen couple of answers on SO like this and this. But I always get some error similar to the following.

Not sure what am I doing wrong. I tried with the following variations, but all giving similar error. Please help.

wget --user "[email protected]" --password "MyWhatEver@pas$w0rd" https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip
wget --user="[email protected]" --password="MyWhatEver@pas$w0rd" https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip
wget --user='[email protected]' --password='MyWhatEver@pas$w0rd' https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip
wget --user [email protected] --password MyWhatEver@pas$w0rd https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip
Invoke-WebRequest : A positional parameter cannot be found that accepts argument
'--password=MyWhatEver@pas$w0rd'.
At line:1 char:1
+ wget --user='[email protected]' --password='MyWhatEver@pas$w0rd'  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
like image 555
VivekDev Avatar asked Oct 01 '16 13:10

VivekDev


People also ask

What is WGET in PowerShell and how to use it?

PowerShell comprises various useful functions and commands are available in PowerShell, which are called cmdlets. The Microsoft version of wget is available as a fundamental command in PowerShell (PS) 3.0 known as Invoke-WebRequest. The wget exists as an alias in the Invoke-WebRequest command.

What is the syntax of Wget command to find the password?

The syntax is: wget options url. wget --user=NAME --password='PASSWORD' url. wget --user=NAME --password='PASSWORD' ftp://url/path/file.name. wget --user=NAME --password='PASSWORD' http://url/path/file.name. Where, --user=userNameHere: Your FTP/HTTP username. --password=passWordHere: Your HTTP/FTP password.

How do I get a user's credentials from PowerShell?

PowerShell. $Credential = $host.ui.PromptForCredential ("Need credentials", "Please enter your user name and password.", "", "NetBiosUserName") This command uses the PromptForCredential method to prompt the user for their user name and password. The command saves the resulting credentials in the $Credential variable.

How to prompt a user for a password in Windows PowerShell?

Beginning in Windows PowerShell 3.0, you can use the Message parameter to specify a customized message on the dialog box that prompts the user for their name and password. The Get-Credential cmdlet prompts the user for a password or a user name and password. By default, an authentication dialog box appears to prompt the user.


1 Answers

It looks like you actually want to run the program wget.exe, but PowerShell has a builtin alias wget for the cmdlet Invoke-WebRequest that takes precedence over an executable, even if the executable is in the PATH. That cmdlet doesn't have parameters --user or --password, which is what causes the error you observed.

You can enforce running the executable by adding its extension, so PowerShell doesn't confuse it with the alias:

wget.exe --user '[email protected]' --password 'MyWhatEver@pas$w0rd' https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip

Note that you should put string literals with special characters like $ in single quotes, otherwise PowerShell would expand something like "MyWhatEver@pas$w0rd" to "MyWhatEver@pas", because the variable $w0rd is undefined.

If you want to use the cmdlet Invoke-WebRequest rather than the wget executable you need to provide credentials via a PSCredential object:

$uri  = 'https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip'
$user = '[email protected]'
$pass = 'MyWhatEver@pas$w0rd' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($user, $pass)

Invoke-WebRequest -Uri $uri -Credential $cred
like image 132
Ansgar Wiechers Avatar answered Sep 27 '22 22:09

Ansgar Wiechers