Powershell oneliner命令使用WebClient从URL下载文件时出错

时间:2018-10-04 18:22:42

标签: powershell powershell-v2.0

正在尝试使用webclient从url下载文件以及用户详细信息。我想以oneliner的身份运行命令,但出现错误。

在Windows上使用cmd.exe执行命令。 python版本是2.7.14

用户密码的末尾带有&字符,因此必须对其进行转义

{code}

C:\>powershell -Command "($wc=new-object net.webclient);$wc.Credentials=new-object System.Net.NetworkCredential("'\"testuser1","testUser1&\"'");$wc.DownloadString('https://ipaddress/artifactory/app/application.exe', 'c:\application.exe')"


AllowReadStreamBuffering  : False
AllowWriteStreamBuffering : False
Encoding                  : System.Text.SBCSCodePageEncoding
BaseAddress               :
Credentials               :
UseDefaultCredentials     : False
Headers                   : {}
QueryString               : {}
ResponseHeaders           :
Proxy                     : System.Net.WebRequest+WebProxyWrapper
CachePolicy               :
IsBusy                    : False
Site                      :
Container                 :

new-object : Cannot find an overload for "NetworkCredential" and the argument count: "1".
At line:1 char:49
+ ($wc=new-object net.webclient);($wc.Credentials=new-object System.Net.NetworkCre ...
+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Cannot find an overload for "DownloadString" and the argument count: "2".
At line:1 char:129
+ ($wc=new-object net.webclient);($wc.Credentials=new-object System.Net.NetworkCre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

{code}

0 个答案:

没有答案