Hello Luc,
this is to get build and version and then compare with reference host.
can you please check the code inside foreach loop .i want to comapre build and version to reference host and print output accordingly .for some reasons output is not what expected.
get-vmhost -location $cluster|select name,version,build
$refhost=read-host "provide the ref host"
foreach($esxi in (get-vmhost -location $cluster))
{
if($esxi.verison -eq "$ref.version" -and $esxi.build -eq "$esxi.build")
{
write-host "$($esxi) matches reference build " -ForegroundColor DarkGreen
}
else
{
write-host "$($esxi) needs to be remediated " -ForegroundColor DarkRed
}}
There were a few typos in there, try like this.
I assume $cluster is assigned earlier
$refhost=Read-Host "provide the ref host"
$ref = Get-VMHost -Name $refhost
foreach($esxi in (Get-VMHost -Location $cluster))
{
if($esxi.version -eq $ref.version -and $esxi.build -eq $ref.build)
{
Write-Host "$($esxi) matches reference build " -ForegroundColor DarkGreen
}
else
{
write-host "$($esxi) needs to be remediated " -ForegroundColor DarkRed
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There were a few typos in there, try like this.
I assume $cluster is assigned earlier
$refhost=Read-Host "provide the ref host"
$ref = Get-VMHost -Name $refhost
foreach($esxi in (Get-VMHost -Location $cluster))
{
if($esxi.version -eq $ref.version -and $esxi.build -eq $ref.build)
{
Write-Host "$($esxi) matches reference build " -ForegroundColor DarkGreen
}
else
{
write-host "$($esxi) needs to be remediated " -ForegroundColor DarkRed
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc it works fine.