Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication powershell中webclient的身份验证错误_Authentication_Powershell_Webclient - Fatal编程技术网

Authentication powershell中webclient的身份验证错误

Authentication powershell中webclient的身份验证错误,authentication,powershell,webclient,Authentication,Powershell,Webclient,我对Powershell比较陌生,所以现在真的不知道该如何处理这个问题。我试图从subversion存储库下载一个文件,但出现了(401)Unauthorized“错误。我可以登录到该站点,并使用IE在同一台机器上使用完全相同的凭据下载该文件 $source=”http://repository/folder/File.exe" $destination=“E:\Temp\File.exe” $wc=新对象System.Net.WebClient $user=“用户” $pwd=convertt

我对Powershell比较陌生,所以现在真的不知道该如何处理这个问题。我试图从subversion存储库下载一个文件,但出现了(401)Unauthorized“错误。我可以登录到该站点,并使用IE在同一台机器上使用完全相同的凭据下载该文件

$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$user=“用户”
$pwd=converttosecurestring-string“password”-AsPlainText-force
$creds=新对象System.Management.Automation.PSCredential-参数列表$user,$pwd
$wc.Credentials=New Object System.Net.NetworkCredential($user,$Creds.GetNetworkCredential().Password,“域”)
$download=$wc.DownloadFile($source,“$destination”)
使用“2”参数调用“DownloadFile”时出现异常:“远程服务器返回错误:(401)未经授权。”

如果这是一个跨平台的问题,你有什么想法吗?如何解决这个问题


谢谢

您是否在iis/apache上使用basic auth?如果是,请尝试以下方法:

$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$credCache=new object System.Net.CredentialCache
$creds=新对象系统.Net.NetworkCredential($user,$pwd)
$credCache.Add($source,“Basic”,$creds)
$wc.Credentials=$credCache
$wc.DownloadFile($source,$destination)

您是否在iis/apache上使用basic auth?如果是,请尝试以下操作:

$source=”http://repository/folder/File.exe"
$destination=“E:\Temp\File.exe”
$wc=新对象System.Net.WebClient
$credCache=new object System.Net.CredentialCache
$creds=新对象系统.Net.NetworkCredential($user,$pwd)
$credCache.Add($source,“Basic”,$creds)
$wc.Credentials=$credCache
$wc.DownloadFile($source,$destination)

感谢您的快速响应。我们确实在Apache上使用了basic auth,并且上面的工作正常。感谢您的快速响应。我们确实在Apache上使用了basic auth,并且上面的工作正常。