Solved

Is it possible to identify locked vmdk file utilizing powershell

Posted on 2014-01-16
4
1,535 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
ID: 39787074
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
ID: 39788509
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
ID: 39788821
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
ID: 39799839
Thanks Qlemo
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Teach the user how to delpoy the vCenter Server Appliance and how to configure its network settings Deploy OVF: Open VM console and configure networking:
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

863 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

24 Experts available now in Live!

Get 1:1 Help Now