How to get RDM list in your VMware infrastructure

How to get RDM list in your VMware infrastructure.

Some time we require information about our virtual machines connected to which RDM .Below are the usefull powershell script to generate a csv report .

VMName: (Display) name of the VM that has the RDM attached to it
GuestDevName: The name of the disk in the VM’s hardware configuration (e.g. “Hard disk 2”)
GuestDevID: The SCSI controller and device ID of the disk in the VM’s configuration (e.g. “scsi0:1”)
VMHost: The ESXi host that runs the VM
HDFileName: The location and name of the RDM mapping file
HDMode: whether the RDM is in virtual or physical compatibility mode
HDSize: the size of the RDM
RuntimeName: The runtime name of the host’s LUN that represents the RDM (e.g. “vmhba1:C0:T2:L61”)
CanonicalName: Its canonical name (naaid)

$vcenter = "192.168.1.1"
$outputFile = "c:\PCLITEST\All-RDMs-" + (get-date -Format yyyy-MM-dd-HHmm) + ".csv"

"Connecting vCenter servers ..."
Connect-VIServer $vcenter -AllLinked

$report = @()
$luns = @{}

"Getting VM(s). Be patient, this can take up to an hour ..."

$vms = Get-VM | Get-View
("Got " + $vms.Count + " VMs ...")

foreach($vm in $vms) {
     ("Processing VM " + $vm.Name + " ...")
     $ctl = $null
     $esx = $null
     write-host -NoNewLine "   Scanning VM's devices for RDMs ..."
     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")){
                    if ($ctl -eq $null) {
                       " Found at least one ..."
                       "   Getting VM's SCSI controllers ..."
                       $ctl = Get-ScsiController -VM ($vm).Name
                    }
                    if ($esx -eq $null) {
                        write-host -NoNewLine "   Getting VM's host ..."
                        $esx = (Get-View $vm.Runtime.Host).Name
                        write-host (": " + $esx)
                    }
                    if ($luns[$esx] -eq $null) {
                        ("   Getting SCSI LUNs of host " + $esx + " ...")
                        $luns[$esx] = Get-ScsiLun -VmHost $esx -luntype disk
                    }
                    $row = "" | select VMName, GuestDevName, GuestDevID, VMHost, HDFileName, HDMode, HDsize, RuntimeName, CanonicalName
                    $row.VMName = $vm.Name
                    $row.GuestDevName = $dev.DeviceInfo.Label
                    $SCSIBus = ($ctl | where {$_.ExtensionData.Key -eq $dev.ControllerKey}).ExtensionData.BusNumber
                    $SCSIID = $dev.UnitNumber
                    $row.GuestDevID = "scsi" + $SCSIBus + ":" + $SCSIID
                    $row.VMHost = $esx
                    $row.HDFileName = $dev.Backing.FileName
                    $row.HDMode = $dev.Backing.CompatibilityMode
                    $row.HDSize = $dev.CapacityInKB
                    $lun = ($luns[$esx] | where {$_.ExtensionData.Uuid -eq $dev.Backing.LunUuid})
                    $row.CanonicalName = $lun.CanonicalName
                    $row.RuntimeName = $lun.RuntimeName
                    $report += $row
               }
          }
     }
     if ($ctl -eq $null) { " None found." }
}

"Exporting report data to $outputFile ..."
$report | Export-CSV -Path $outputFile

Source Link

Below are the output of file

All-RDMs

Leave a Comment