Please enable Javascript for better experience...
Exception calling "DownloadFile" with "2" argument(s): "Unable to connect to the remote server
By Pranay Jha | Jun 5, 2020 | In Articles | Total Views [ 799 ]
Taged In
(0 Like)


I am using below script to find ESXi compatibility for vSphere environment. While using script, it is failing with the error. My internet is running with proxy and requires credentials. Therefore, it is not connecting to invoked link and generating error.

PowerCLI Script to verify Hardware ESXi 7.0 Support


Exception calling "DownloadFile" with "2" argument(s): "Unable to connect to the remote server"

At C:\Pranay\Script\ESXi_Compatiblity\ESXi_Compatiblity.ps1:13 char:1

+ (New-Object System.Net.WebClient).DownloadFile("https://raw.githubuse ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : WebException



{Solution Credit: LucD}

In that case we can try to set a default value for those Proxy parameters on Invoke-WebRequest, for all invocations. Something like this;


$scope = Get-VMHost

$user = 'user'

$pswd = 'pswd'

$cred = New-Object PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force)

$global:PSDefaultParameterValues = @{

        'Invoke-WebRequest:Proxy' = 'http://proxy:porxyport'

        'Invoke-WebRequest:ProxyCredential'= $cred


$sWebRequest = @{

    Uri = ''

    OutFile = "$Env:temp\Check-HCL.ps1"


Invoke-WebRequest @sWebRequest

. $Env:temp\Check-HCL.ps1

$check = Check-HCL $scope

foreach ($esx in $check){

  Write-Host "$($esx.VMHost) ($($esx.Model)): "  -NoNewline


    if ($esx.SupportedReleases -match "7.0"){

      Write-Host "ESXi 7.0 supported" -ForegroundColor Green

    } else {

      Write-Host "ESXi 7.0 unsupported" -ForegroundColor Red


  } else {

    Write-Host "unknown"



Thanks for visiting here. Share this article if you found it useful.
Like Facebook Page
Connect to twitter
Subscribe my Channel
Connect over Linkedin
Share this on Social Media

About the Author

Pranay Jha
Pranay Jha
Founder, Contributer

Public profile: user/profile/99900000

Follow me

facebook linkedin twitter G+ VMTN youtube

Thank you for visiting my profile. I am Pranay Jha, bring along a total of 11+ years of extensive experience with me in Information Technology sector for organizations from small business to large enterprises, wherein my current assignment I am associated with IBM as a Technical Solution Architect for Virtualization platform. I am vExpert x 3 (16/17/18), VCIX-DCV, VCAP5/6-DCD, VCAP5-DCA, VCP7-CMA, VCP5/6-DCV, VCA-DCV, VCA-Cloud, VSP, VCE-CIA, MCITP, MCSE, MCSA(Messaging). I am also an Independent blogger and founder of and I can be reached via email at or Direct Message via Contact Us form.

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID
Facebook Likes