我试图设置自动下载和安装文件的过程。每次运行脚本时,我都会遇到错误,尽管我已经从周日起尝试了七种不同的更改,但它仍然给我报错。
脚本如下:
if (test-path $java_path)
{
Write-Output "Java already installed. Skipping script"
exit 0
}
else
{
$source = "http://our.server.com/java-installer.zip"
$destination = "c:\CHPACS"
$client = new-object System.Net.WebClient
$client.DownloadFile($source, $destination)
}
我得到的错误信息是
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At C:\ps_script\testjava.ps1:41 char:31
+ $client.DownloadFile <<<< ($source, $destination)
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DotNetMethodException
我需要创建一个函数才能使这个工作正常吗?
谢谢。
$error[0].Exception.ToString()
并发布结果吗?这将提供更详细的信息。 - latkin