0
我收到此錯誤嘗試將文件下載到一個目錄在遠程服務器上
異常調用「DownloadFile」與「2」參數(S):「一個Web客戶端請求期間發生異常。」
從這個腳本
$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服務器上運行2008
腳本目的是file.zip下載到遠程服務器(也有數百臺服務器,所以我不能每次提示輸入密碼)並查看下載的進度條。
任何想法?
+1不過,我會做'$ url'和'$ path'腳本塊參數,並通過調用' - 命令-ArgumentList ...'通過他們。使腳本更易於維護。 – 2013-03-27 09:23:32
您可能需要在$ command block的末尾調用$ client.dispose() – Cirem 2014-06-10 19:33:20