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 [ 4894 ]
Taged In
(0 Like)
Rate

Problem:

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


Error:


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:

{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 = 'https://raw.githubusercontent.com/fgrehl/virten-scripts/master/powershell/Check-HCL.ps1'

    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){

    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 https://www.facebook.com/VMwareInsight/
Connect to twitter https://twitter.com/imPranayK
Subscribe my Channel https://www.youtube.com/vmwareinsight
Connect over Linkedin https://in.linkedin.com/in/impranayk
Share this on Social Media

About the Author

Pranay Jha
Pranay Jha
Founder, Contributer VMwareInsight.com

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 http://vmwareinsight.com and https://cloudpathshala.com. I can be reached via email at pranay1988jha@gmail.com or Direct Message via Contact Us form.

 
Please SignUp/Login to comment...

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