VMware Cloud Community
Chakoe1
Contributor
Contributor

Cleanup Vcenter - find empty Hosts

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

0 Kudos
4 Replies
sajal1
Hot Shot
Hot Shot

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"

    }

}

0 Kudos
Chakoe1
Contributor
Contributor

Hey,

okay, this works fine...but it takes a very long time this script walks through 1.000 Hosts....

Is there any faster way ?

0 Kudos
sajal1
Hot Shot
Hot Shot

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.

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos