2016-10-01 157 views
0

我已經看到幾個關於SO的答案,如thisthis。但我總是會遇到類似於以下的錯誤。如何在使用用戶名和密碼的PowerShell控制檯中使用wget

不知道我在做什麼錯。我嘗試了以下變化,但都給出了類似的錯誤。請幫忙。

wget --user "[email protected]" --password "[email protected]$w0rd" https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip 
wget --user="[email protected]" --password="[email protected]$w0rd" https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip 
wget --user='[email protected]' --password='[email protected]$w0rd' https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip 
wget --user [email protected] --password [email protected]$w0rd https://bitbucket.org/WhatEver/WhatEverBranchName/get/master.zip 
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 
'[email protected]$w0rd'. 
At line:1 char:1 
+ wget --user='[email protected]' --password='[email protected]$w0rd' ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException 
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

回答

1

它看起來像你真的想運行的程序wget.exe,但PowerShell提供了對於需要precedence了一個可執行文件,即使該可執行文件是在PATH該cmdlet Invoke-WebRequest一個內置別名wget。該cmdlet沒有參數--user--password,這是導致您觀察到的錯誤的原因。

您可以強制通過添加它的擴展運行可執行文件,所以PowerShell不會與別名混淆:

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

請注意,你應該把字符串文字用特殊字符,如單引號中$,否則因爲變量$w0rd未定義,PowerShell將擴展如"[email protected]$w0rd""[email protected]"

如果你想使用該cmdlet Invoke-WebRequest而非wget可執行文件,你需要通過一個PSCredential目的是提供憑據:

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

Invoke-WebRequest -Uri $uri -Credential $cred 
+0

謝謝你,有道理你說什麼。 – VivekDev

相關問題