Solved

Is it possible to identify locked vmdk file utilizing powershell

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Teach the user how to use create log bundles for vCenter Server or ESXi hosts Open vSphere Web Client: Generate vCenter Server and ESXi host log bundle:  Open vCenter Server Appliance Web Management interface and generate log bundle: Open vCenter Se…
Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…

773 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