Solved

Is it possible to identify locked vmdk file utilizing powershell

Posted on 2014-01-16
4
1,613 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 69

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 69

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

A brief introduction to what I consider to be the best editor for PowerShell.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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:
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

730 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