VMware Cloud Community
ThejasKV
Contributor
Contributor

How to list only the classic ESXs

I am having mixture of ESX and ESXi in my 4.1 vCenter Server environment. I want to list only the classic ESXs using powercli command. Please help.

0 Kudos
4 Replies
vlife201110141
Enthusiast
Enthusiast

connect-VIServer -server xxx -user xxx -password xxx

$vmhosts =

Get-VMHost

foreach($esx in $vmhosts){

$esxname = $esx.extensiondata.config.product.name

if($esxname -eq "VMware ESX") {

Write-Host $esx.name

}}

0 Kudos
LucD
Leadership
Leadership

That script will produce the desired result, but you can make it a bit simpler (and more PowerShell like).

Something like this

Get-VMHost | 
where {$_.extensiondata.config.product.name -eq "VMware ESX"} | 
Select Name 

Everything in a pipeline construct and no foreach (Glenn will like this).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mattboren
Expert
Expert

Hello, ThejasKV-

The script that vlife provided will do exactly what you asked.  Another way to do it, though, if you have speed in mind, is to use the Get-View cmdlet instead of the Get-VMHost cmdlet.  You can use the -Filter parameter to make things even faster.  Like:

Get-View -ViewType HostSystem -Property Name -Filter @{"Config.Product.Name" = "^VMware ESX$"} | Select Name

In testing with about 175 hosts, the Get-VMHost route took about 190 seconds, whereas the Get-View method took about 7 seconds.  I'm for the fastness.

0 Kudos
ThejasKV
Contributor
Contributor

Thanks a lot for the quick response.

0 Kudos