I am trying to setup to download need files to automate and install process. I keep getting errors ever time I run the script and I have changed it seven ways from sunday and it still gives me errors.
The script is:
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)
}
The error message that I am getting is
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
Do I need to create a function to make this work properly?
Thank you:
If you look at the MSDN documentation for the DownloadFile
method, you'll notice that the second parameter is a filename, not a directory. So, if you re-define $destination
to something like:
$destination = "c:\CHPACS\java-installer.zip"
then it should work.
Check secondly that the file that you're trying to download isn't open or being executed at the moment. This exception will be raised if the file is in use.
You should give a file name as David said + the folder should exist.
In my case the URL wasn't reachable on the machine I was trying to execute the script. Had to enable proxy rules to scope it to the machine to download the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With