繁体   English   中英

如何在powershell中使用默认会话凭证bitstransfer proxy

[英]How to use use default session credentials bitstransfer proxy in powershell

我正在尝试使用“start-bitstransfer”cmdlet自动下载某些文件,但我应该使用代理。

我使用“get-credentials”没有问题下载文件没有问题,但我想避免提示当前的用户会话。 $ mycred = get-credential Start-BitsTransfer -proxyusage override -proxylist @(“myproxy.com:8080”)-proxycredential $ mycred -Proxyauthentication Ntlm http://go.microsoft.com/fwlink/?LinkId =76054。\\ wsusscn2 。出租车

但是,当我尝试使用defaultcredentials以避免提示它时,$ mycred = [System.Net.CredentialCache] :: DefaultCredentials

我得到的错误与“用户名”有关,如下所示:Start-BitsTransfer:无法处理参数'ProxyCredential'上的参数转换。 用户名

如何使用默认用户会话凭据? 我已经尝试过我见过的其他样本将凭据传递给代理,但没有一个正常工作。 有什么建议吗?

问候

由于处理异步文件传输的基础.NET方法, Start-BitsTransfer似乎无法使用默认凭据。

如果Start-BitsTransfer不是硬盘要求,我会推荐WebClient

一个创建$global:webClient对象的函数;

function Set-WebClient {
   if(!($global:webClient)){
      try   {  $global:webClient = New-Object System.Net.WebClient     }
      catch {  $M="WebC:  Unable to setup WebClient" ; write-output $M }
      if($global:webClient){
         try   { $global:webClient.Proxy = [System.Net.WebRequest]::DefaultWebProxy }
         catch { $M="WebC:  Unable to set WebClient Proxy" ; write-output $M        }
         if($global:webClient.Proxy){
            try   { $global:webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials }
            catch { $M="WebC:  Unable to set WebClient Proxy Credentials for Authorization " ; write-output$M     }
         }
      }
   }
}  ## end function Set-WebClient

现在调用该函数,然后让.Net对象下载该文件。

Set-WebClient

$url    = "http://go.microsoft.com/fwlink/?LinkId=76054"
$output = "$((Get-Location).Path)\wsusscn2-$($DT).cab"

$webClient.DownloadFile($url,$output) ## downloads the file

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM