The IC doesn't know if you've got those disks shared an in use by another ESXi host, it's very common to have a SAN on the backend and multiple hosts accessing the same storage device. In this case there's no way to know which hosts are accessing which machines, the scenario you describe only makes sense if you've got a single host - which is not the typical scenario for many of VMware's corporate customers.
Using the RCLI or shell you could iterate through all existing machines and then compare that to a list of what's on disk. If you've got disks shared between hosts however, then things become a lot more complicated and you'd need to iterate through the devices on each machine as well.
Update: Right, now it's more of a nuts n bolts scripting/programming question ;)
Starting with the RCLI documentation I'd probably do something like using vmware-cmd -l
to list all registered machines on the host. Then using vifs
download the config files, grep
through those looking for mentions of virtual disks (.vmdk
) and storing all those in a file.
Part two, would be writing a script to do a recursive directory listing, again using vifs
, running grep
again on that to only include .vmdk
and .vmx
files. Now you've got two lists, pipe these through sort
and then diff
the results to find out what .vmx
files are not registered on the machine and what .vmdk
files are not in use by any active VM. And then you have your candidates for deletion :)