Notes of a scripter

PowerCLI to get information about RDM connected to VM.

In my work environment when we use MS SQL, so we have to build failover clusters.  This means the use of RDM (Raw Device Mappings) LUNs.  So you have to connect the RDM LUNs to the first system and them connected them to the second system using the disk file names.  This is not a big deal, but it is nice to speed this process of mapping the drive on the second system, and cut and paste is your friend.

$VM = "VMNameHere"
Get-vm $VM | Get-HardDisk | Where {$_.Disktype -eq "RawPhysical"} | Select CapacityGB, Filename
Sample output from basic script

This will get you the basic information that is needed to map the drives on the second node of the cluster, but it would be nice to get some additional information.

$VM = "VMNameHere"
$VmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $VM}
foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {
            foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {
                Get-VM $VM | Select Name, @{N="DiskName";E={$VirtualDiskDevice.DeviceInfo.Label}}, @{N="CanonicalName";E={(Get-VM $VM | Get-Harddisk -Name ($VirtualDiskDevice.DeviceInfo.Label)).ScsiCanonicalName}}, @{N="SCSI_Id";E={"$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"}}, @{N="DiskFile";E={$VirtualDiskDevice.Backing.FileName}}, @{N="DiskSize(GB)";E={$VirtualDiskDevice.CapacityInKB * 1KB / 1GB}}
            }
}

 

Sample output of script

With this it will get the name of the server you are working with, the disk file name, SCSI canonical name, SCSI ID, disk file name, and the disk size.  With this output, you can easily cut and paste the disk file name into the second node without having to browse the datastore to find the VMDK pointer file to attach.  Also have the SCSI node ID so you make make sure that they match on both nodes.

-Stuart

Exit mobile version