我收到此错误
使用“2”参数调用“DownloadFile”的异常:“WebClient请求期间发生异常。”
从此脚本
$username = "Administrator"
$password = "PASSWORD"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$url = "http://www.website.com/file.zip"
$path = "C:\file.zip"
$client = new-object System.Net.WebClient
$client.DownloadFile( $url, $path )
Invoke-Command -ComputerName 69.69.69.69 -ScriptBlock { $client } -credential $cred
在Windows Web Server 2008上运行
脚本的目的是将file.zip下载到远程服务器(有数百台服务器,因此每次都不会提示输入密码)并查看下载的进度条。
有什么想法吗?
答案 0 :(得分:2)
尝试
$username = "Administrator"
$password = "PASSWORD"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$command = {
$url = "http://www.website.com/file.zip"
$path = "C:\file.zip"
$client = new-object System.Net.WebClient
$client.DownloadFile( $url, $path )
}
Invoke-Command -ComputerName 69.69.69.69 -ScriptBlock $command -credential $cred