VMware: List all RDM disks in Hosts and Virtual Machines via PowerCLI

13

To prepare a SAN to SAN migration I need to list all virtual machines with RAW Device Mappings, I found a very nice script at Pastebin (I’ve this you’re script, please comment to receive the credits), the script:

$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, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName
                    $row.VMName = $vm.Name
                    $esx = Get-View $vm.Runtime.Host
                    $row.VMHost = ($esx).Name
                    $row.HDDeviceName = $dev.Backing.DeviceName
                    $row.HDFileName = $dev.Backing.FileName
                    $row.HDMode = $dev.Backing.CompatibilityMode
                    $row.HDSize = $dev.CapacityInKB
                    $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName
                    $report += $row
               }
          }
     }
}
$report

image

Ps. the script can take a while to list…

About Author

13 thoughts on “VMware: List all RDM disks in Hosts and Virtual Machines via PowerCLI

  1. Hi Matheen, the best thing you can do is copy the content of the script to notepad, then you save the file as “list_rdm.ps1”

    Once you opened PowerCLI and connected vCenter server or host you can run the list_rdm.ps1 and you will get the result

  2. hi all,

    forgive me if i am asking worst, how can i run the above script from power cli, where i can learn about scripting from the scratch.

    thanks in advance.

  3. Search for a file named report. Or change the first line and the last two lines in the script to “report.tom”. Then, after the script runs, search for “report.tom”.

    OR
    add this line to the end of the script:
    Export-CSV -report.tom.csv

    OR
    copy the script into Kornshell, CShell, Bourne Shell or BASH or otherwise,as an executable unix script. Then invoke it from the command line by just typing in ‘report.tom’ . It will effectively be in an executable format I.E. (report.tom.exe). And May The Force Be With you!

Leave a Reply

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