VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

getting version and build of esxi and comapring to ref host_powercli

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

}}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Luc it works fine.

0 Kudos