I have been getting the below error when i try to download file from a https URL. I am using Power Shell 3.0
Shell Script
$Username = 'user'
$Password = 'password'
$Url = "url"
$Path = "path"
$WebClinet = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $Url, $Path )
Error :
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." At line:7 char:1 + $WebClient.DownloadFile( $Url, $Path )
Any suggestions?
Wrap you existing powershell code in a try catch block and write out the exception details in order to understand what actual error is causing the problem.
Try
{
$Username = 'user'
$Password = 'password'
$Url = "url"
$Path = "path"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $Url, $Path )
}
Catch [Exception]
{
Write-Host $_.Exception | format-list -force
}
And also there is a typo in your code. Check your variable names.
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