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.
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
}}
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
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.
Thanks a lot for the quick response.