?
Solved

Is it possible to identify locked vmdk file utilizing powershell

Posted on 2014-01-16
4
Medium Priority
?
1,705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 70

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 70

Accepted Solution

by:
Qlemo earned 1500 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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 quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Teach the user how to configure vSphere clusters to support the VMware FT feature Open vSphere Web Client: Verify vSphere HA is enabled: Verify netowrking for vMotion and FT Logging is in place or create it: Turn On FT for a virtual machine: Verify …
This video shows you how easy it is to boot from ISO images for virtual machines with the ISO images stored on a local datastore on the ESXi host.
Suggested Courses

777 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