如何在powershell中使用默认会话凭据bitstransfer代理
我正在尝试使用“start-bitstransfer”cmdlet自动下载一些文件,但我应该使用代理 如果我使用“获取凭据”,则没有问题下载文件没有问题,但我希望避免提示当前用户会话。 $mycred=获取凭证 启动BitsTransfer-proxyusage override-proxylist@(“myproxy.com:8080”)-proxycredential$mycred-Proxyauthentication Ntlm。\wsusscn2.cab 但是当我试图使用defaultcredentials来避免提示时 $mycred=[System.Net.CredentialCache]::DefaultCredentials 我发现与“用户名”相关的错误如下: Start BitsTransfer:无法处理参数“ProxyCredential”的参数转换。用户名 如何使用默认用户会话凭据?我尝试过使用我见过的其他示例将凭据传递给代理,但都没有成功。 有什么建议吗如何在powershell中使用默认会话凭据bitstransfer代理,powershell,proxy,networkcredentials,microsoft-bits,credentialscache,Powershell,Proxy,Networkcredentials,Microsoft Bits,Credentialscache,我正在尝试使用“start-bitstransfer”cmdlet自动下载一些文件,但我应该使用代理 如果我使用“获取凭据”,则没有问题下载文件没有问题,但我希望避免提示当前用户会话。 $mycred=获取凭证 启动BitsTransfer-proxyusage override-proxylist@(“myproxy.com:8080”)-proxycredential$mycred-Proxyauthentication Ntlm。\wsusscn2.cab 但是当我试图使用defaultc
关于由于处理异步文件传输的底层.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
由于处理异步文件传输的底层.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