I was wondering if anyone knew if it were at all possible to utilize Powershell to identify whether or not a VMDK file had a lock on it. I am familiar with the method of connecting to the host and running vmkfstools -d against the vmdk however powershell would be a lot faster. I recently identified numerous potential floating non-attached vmdk (zombie) files but before I delete them I want to ensure they are not tethered to anything.
I am pasting in a screenshot of the method I am aware of with the information I would be looking for if you connect to the host directly.
The circled items are what I am most interested in obtaining. Mode indicates if the file is locked and the second item is the host that has the file lock.
- mode 0 = no lock
- mode 1 = is an exclusive lock (vmx file of a powered on VM, the currently used disk (flat or delta), *vswp, etc.)
- mode 2 = is a read-only lock (e.g. on the ..-flat.vmdk of a running VM with snapshots)
- mode 3 = is a multi-writer lock (e.g. used for MSCS clusters disks or FT VMs).