0

我收到此错误

使用“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下载到远程服务器(有数百台服务器,所以不能每次都提示我输入密码)并查看下载的进度条。

有任何想法吗?

4

1 回答 1

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
于 2013-03-27T04:29:03.833 回答