VMware virtual infrastructure Remote CLI search for unused machines / disks in ESX / i
In VMware ESX / i, how can I use VMware Virtual Infrastructure Remote CLI to find unused machines / disks? I have a huge inventory and a lot of files on my disk and I want to find files that are candidates for deletion.
I want to determine if there will be
- a
vmdk
disk is used by any machinevmx
on the host, or - a
vmx
machine exists in the inventory on the host.
Surely there is some clever method for finding this? If not VIRCLI, then maybe something else? Or do I need a virtual center for this?
EDIT: This is the only host that does not use computers or disks with any other host.
source to share
The IC doesn't know if you have these disks in use by another ESXi host, it is very common to have a SAN on the backend and multiple hosts accessing the same storage device. In this case, there is no way to know which hosts are accessing the machines, the scenario you describe only makes sense if you have a single host, which is not the typical scenario for many VMware enterprise clients.
Using RCLI or the shell, you can iterate over all existing machines and then compare them against a list of what's on disk. However, if you have disks shared between hosts then things get much more complicated and you will need to iterate through the devices on each machine.
Update: Correct, now this is more questions about scripting / programming nuts n bolts;)
Starting with the RCLI documentation I would probably do something like using vmware-cmd -l
to list all registered machines on the host. Then using vifs
load the config files grep
via those looking for virtual disk references ( .vmdk
) and save all files in the file.
Part two, will write a script to make a recursive list of directories, using vifs
again, running again grep
to include only files .vmdk
and .vmx
. You now have two lists, swipe them through sort
and then the diff
results to see which files are .vmx
not checked in on the computer and which .vmdk
files are not being used by any active virtual machine. And then you have candidates for deletion :)
source to share