A friend of mine asked me if there was a way to find out which VM’s were connected to a certain RDM disk. I’ve been looking all over but couldn’t find a simple command to do this. So I ended up on the forums and found a powershell script which creates a list with all the necessary info one would like to have:
$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq “VirtualDisk”){
if(($dev.Backing.CompatibilityMode -eq “physicalMode”) -or
($dev.Backing.CompatibilityMode -eq “virtualMode”)){
$row = “” | select VMName, HDDeviceName, HDFileName, HDMode
$row.VMName = $vm.Name
$row.HDDeviceName = $dev.Backing.DeviceName
$row.HDFileName = $dev.Backing.FileName
$row.HDMode = $dev.Backing.CompatibilityMode
$report += $row
}
}
}
}
$report
All credits for this great script go to LucD!
Jason Boche says
Nice one. I’ve got to get that useful scripts repository started…
William says
Hi Duncan,
This was a task I had before which I could not figure out, but your posting made me think about the issue again. I also had posted on the VMTN forums (http://communities.vmware.com/message/1090685) asking for a method and I had not realized that there was a way. Taking the idea and your posting, I came up with a quick/dirty script that can be ran on both ESX 3.5+ and ESXi to capture this same data set. You can find the shell script at:
http://www.engr.ucsb.edu/~duonglt/rdm/
I’m always open to more options since this one would require a Windows system and having powershell installed. This would allow users to run on their standard and beloved Service Console or ESXi (which requires SSH Console to be opened up). I’m also looking for a way to accomplish this on VIMA, since it’s the “centralize” management utility that VMware is pushing for, but the commands are pretty slow and still need to spend more time looking into the available command sets.
-W