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;
$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"
}
}