Hi , we have to remove a large amount of ESX-Servers step by step, when they´re "empty"...
So i tried to bult a little Script which shows me the empty ESX-Servers:
Get-VMHost v100spwesx* |SOrt Name | where { (Get-VM).Count -eq "0" } | Select Name
My questions are:
1) Is there a faster way to get the results, for example with some "Get-Views"
2) Is my Script pointing into the right direction or is there a much better way?
Thx in advance
Chakoe
You need to modify your query like
Get-VMHost v100spwesx* | Where { !(Get-VM -Location $_.Name) } | Select Name
Or to do it through API
foreach($hosts in Get-VMHost){
if (!$hosts.Extensiondata.Vm){
Write-Host $hosts.Name "empty"
}
}
Hey,
okay, this works fine...but it takes a very long time this script walks through 1.000 Hosts....
Is there any faster way ?
In any case you need to check each and every ESXi host, so that can not be avoided. Considering 1000 hosts, it will take some time.
Using the first method, you are querying twice, using Get-VMHost once and then for each ESXi host you are using Get-VM. It will take more time.
Check the below method:
Get-VMHost | Get-View | Where{ !$_.VM } | Select Name
This should be the quickest.
Try like this, should be faster
Get-View -ViewType HostSystem -Property Name,VM |
where{!$_.VM} | select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference