Virtu-Al.Net

Virtually everything is poshable

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 Responses to “List VM’s with RDM”

  • William says:

    Here is another solution that does not require PS:

    http://www.engr.ucsb.edu/~duonglt/vmware

    search for rdm.sh

  • Virtu-Al says:

    Thanks William, that’s usefull

  • Ccalvin says:

    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

  • Jay says:

    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.

  • Sjoerd Hooft says:

    Hi,

    thanks for the script. I made a few small changes because I got the same error as Jay. It needed an ENTER inside that line. I also added the vmhost and the virtualmode disks as suggested by ccalvin. I posted it on my own site:
    http://www.warmetal.nl/powerclirdmvms
    of which I hope you’re ok with Alan?

  • Virtu-Al says:

    Of course, great to see improvements!

  • Sal says:

    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?

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>