Solved

Is it possible to identify locked vmdk file utilizing powershell

Posted on 2014-01-16
4
1,482 Views
Last Modified: 2014-01-22
Hi Everyone,

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.

Locked File ExampleThe 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).
0
Comment
Question by:RyanMyers83
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Is the script at http://techdump.co.uk/2011/10/check-for-orphaned-vmdk-files-in-vcenter-using-powercli/ to find orphaned VMDKs via PowerCLI what you search for?
0
 

Author Comment

by:RyanMyers83
Comment Utility
Hi Qlemo,

Not quite what I'm looking for although thats a cool script.  I actually use RVtools (free app) to identify what should be orphaned files.  My Goal is to verify that the files are in fact not in use by anything by utilizing powershell to accomplish the task I pasted above.  Perhaps it may be a bit redundant to do so but I'm working in a production environment and I would rather be on the safer side.
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
You need to be more precise. The script I linked to shows all VMDKs which are not part of VM definitions in vCenter. That's very safe, as those cannot be in use by anyone.

What it doesn't is looking for offline VMs. Any VM displaying in the vCenter inventory is considered to be "valid". If you want to consider offline VMs' disk files as orphaned, we can do that by using
$arrUsedDisks = Get-View -ViewType VirtualMachine |
  ? { $_.Runtime.PowerState -eq 'poweredoff' } | 
  % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}

Open in new window

0
 

Author Closing Comment

by:RyanMyers83
Comment Utility
Thanks Qlemo
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Teach the user how to edit .vmx files to add advanced configuration options Open vSphere Web Client: Edit Settings for a VM: Choose VM Options -> Advanced: Add Configuration Parameters:
Teach the user how to install and configure the vCenter Orchestrator virtual appliance Open vSphere Web Client: Deploy vCenter Orchestrator virtual appliance OVA file: Verify vCenter Orchestrator virtual appliance boots successfully: Connect to the …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now