While using script form below link to check ESXi compatibility, it is failing with the error. My internet is running without proxy but internet requires credentials.
https://www.virten.net/2020/04/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
I believe that below download is failing when connecting to internet. Is there any way I can use it manually rather downloading from internet through script.
(New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/fgrehl/virten-scripts/master/powershell/Check-HCL.ps1", "$Env:temp\Check-HCL.ps1")
Ok, 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"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suggest you ask the question via the comments of that blog post.
Btw, I find it very cynical that you beg for points in your footer, while you yourself never bother to reply on your threads nor ever even mark any response as correct.
Sorry, but this is where my community engagement stops.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My bad that I didn't notice to mark. It was not intentionally and I must offer apology.
I have no problem with that.
You're not the only one :smileygrin:
I just have an absolute horror of that phrase "Please consider marking this answer "correct" or "helpful" if you found it useful" many have in their footer.
On your question, I'm not sure why the script author uses that .NET method for the download.
There is a cmdlet for that, which also allows passing a proxy and credentials.
Check if you get it to work like that.
$user = 'user'
$pswd = 'pswd'
$cred = New-Object PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force)
$sWebRequest = @{
Uri = 'https://raw.githubusercontent.com/fgrehl/virten-scripts/master/powershell/Check-HCL.ps1'
OutFile = "$Env:temp\Check-HCL.ps1"
Proxy = 'http://proxy:porxyport'
ProxyCredential = $cred
}
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"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It is giving below error. It seems that it is also invoking web request from Check-HCL.ps1 which is a link in parent script.
Invoke-WebRequest : Unable to connect to the remote server
At C:\Users\user\AppData\Local\Temp\104\Check-HCL.ps1:26 char:21
+ ... iReleases = Invoke-WebRequest -Uri http://www.virten.net/repo/esxiRel ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Ok, 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"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, It is working perfectly as expected. Thanks for quick response. You and your scripting skills are beyond imagination. . LucD