List VM’s with RDM

I was asked if it was possible to list all VM’s with Raw Disk Mappings on twitter, a quick search of the VI Toolkit community showed that LucD had already achieved this, I have copied the code below for reference:

Connect-VIServer MYVISERVER
$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"){
 $row = "" | select VMName, HDDeviceName, HDFileName
 $row.VMName = $vm.Name
 $row.HDDeviceName = $dev.Backing.DeviceName
 $row.HDFileName = $dev.Backing.FileName
 $report += $row
 }   } }}$report

7 thoughts on “List VM’s with RDM

  1. Sal

    I got your script to find ” list the VMs with RDM”. However I need to know how many RDMs are connected to each VM?

    I am running into Lun limitation and wants to see where all my luns got consumed?

  2. Jay

    Hrm. Maybe there is some ignorance here on my part (wouldn’t be the first time!) but this is erroring out for me.

    Unexpected token ‘vms’ in expression or statement.
    At line:1 char:18
    + $report = @()$vms <<<< = Get-VM | Get-View + CategoryInfo : ParserError: (vms:String) [], ParentContainsErro rRecordException + FullyQualifiedErrorId : UnexpectedToken vCenter 4.1, vSphere 4.0 Any suggestions would be greatly appreciated.

  3. Ccalvin

    I suggest one adjustment. This is not inclusive of virtual compatability mode RDMs. Changing:
    if($dev.Backing.CompatibilityMode -eq “physicalMode”){
    to
    if(($dev.Backing.CompatibilityMode -eq “physicalMode”) -or ($dev.Backing.CompatibilityMode -eq “virtualMode”)){

    will fill that gap

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.