Visitors

VMware PowerCLI script to get VM's virtual and RDM disk information

I have been tasked to migrate several VMs with RDM disks between storage arrays / datastores. The data LUNs have been migrated/copied and all was left is the migration of the VM configuration files and RDM pointers. To make matter even worse, VMs in question were Oracle RAC clustered VMs therefore is was imperative to migrate the disks and SCSI IDs in “like it was before” way.

Let me start with a script that lists VM’s virtual and RDM disks, SCSI IDs and Disk Device Name and files names:

$DiskInfo= @()
foreach ($VMview in Get-VM node001, node002 | Get-View){
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})) {
$VirtualDisk = "" | Select VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize
$VirtualDisk.VMname = $VMview.Name
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
$DiskInfo += $VirtualDisk
}}}
$DiskInfo | sort VMname, Diskname | Export-Csv -Path 'd:DiskInfo.csv'
# You can also use FT -AutoSize or Out-GridView if it helps

The script output shows everything you need to complete the migration successfully:

VMname SCSIController DiskName SCSI_ID DeviceName DiskFile DiskSize
Node001 SCSI controller 0 Hard disk 1 00:00 [My_Datastore_1] Node001/Node001.vmdk 70
Node001 SCSI controller 1 Hard disk 10 01:08 vml.0200240000514f0c5ff200006e587472656d41 [My_Datastore_1] Node001/Node001_11.vmdk 2
Node001 SCSI controller 1 Hard disk 11 01:09 vml.0200470000514f0c5ff200006f587472656d41 [My_Datastore_1] Node001/Node001_12.vmdk 10
Node001 SCSI controller 1 Hard disk 12 01:10 vml.0200480000514f0c5ff2000070587472656d41 [My_Datastore_1] Node001/Node001_13.vmdk 2
Node001 SCSI controller 0 Hard disk 2 00:01 vml.02000d0000514f0c5ff2000047587472656d41 [My_Datastore_1] Node001/Node001_1.vmdk 30
Node001 SCSI controller 0 Hard disk 3 00:02 vml.0200290000514f0c5ff2000048587472656d41 [My_Datastore_1] Node001/Node001_2.vmdk 30
Node001 SCSI controller 1 Hard disk 4 01:00 vml.02002c0000514f0c5ff200004b587472656d41 [My_Datastore_1] Node001/Node001_3.vmdk 5
Node001 SCSI controller 1 Hard disk 5 01:06 vml.0200450000514f0c5ff2000064587472656d41 [My_Datastore_1] Node001/Node001_9.vmdk 100
Node001 SCSI controller 1 Hard disk 6 01:04 vml.0200440000514f0c5ff2000063587472656d41 [My_Datastore_1] Node001/Node001_7.vmdk 5
Node001 SCSI controller 1 Hard disk 7 01:03 vml.0200430000514f0c5ff2000062587472656d41 [My_Datastore_1] Node001/Node001_6.vmdk 125
Node001 SCSI controller 1 Hard disk 8 01:05 vml.0200420000514f0c5ff2000061587472656d41 [My_Datastore_1] Node001/Node001_8.vmdk 5
Node001 SCSI controller 0 Hard disk 9 00:03 [My_Datastore_1] Node001/Node001_10.vmdk 21
Node002 SCSI controller 0 Hard disk 1 00:00 [My_Datastore_2] Node002/Node002.vmdk 70
Node002 SCSI controller 1 Hard disk 10 01:08 vml.0200240000514f0c5ff200006e587472656d41 [My_Datastore_1] Node001/Node001_11.vmdk 2
Node002 SCSI controller 1 Hard disk 11 01:09 vml.0200470000514f0c5ff200006f587472656d41 [My_Datastore_1] Node001/Node001_12.vmdk 10
Node002 SCSI controller 1 Hard disk 12 01:10 vml.0200480000514f0c5ff2000070587472656d41 [My_Datastore_1] Node001/Node001_13.vmdk 2
Node002 SCSI controller 0 Hard disk 2 00:01 vml.02002a0000514f0c5ff2000049587472656d41 [My_Datastore_2] Node002/Node002_1.vmdk 30
Node002 SCSI controller 0 Hard disk 3 00:02 vml.02002b0000514f0c5ff200004a587472656d41 [My_Datastore_2] Node002/Node002_2.vmdk 30
Node002 SCSI controller 1 Hard disk 4 01:00 vml.02002c0000514f0c5ff200004b587472656d41 [My_Datastore_1] Node001/Node001_3.vmdk 5
Node002 SCSI controller 1 Hard disk 5 01:06 vml.0200450000514f0c5ff2000064587472656d41 [My_Datastore_1] Node001/Node001_9.vmdk 100
Node002 SCSI controller 1 Hard disk 6 01:04 vml.0200440000514f0c5ff2000063587472656d41 [My_Datastore_1] Node001/Node001_7.vmdk 5
Node002 SCSI controller 1 Hard disk 7 01:03 vml.0200430000514f0c5ff2000062587472656d41 [My_Datastore_1] Node001/Node001_6.vmdk 125
Node002 SCSI controller 1 Hard disk 8 01:05 vml.0200420000514f0c5ff2000061587472656d41 [My_Datastore_1] Node001/Node001_8.vmdk 5
Node002 SCSI controller 0 Hard disk 9 00:03 [My_Datastore_2] Node002/Node002_3.vmdk 21

To migrate both VMs to another Datastore you just need to (BTW, please refer to ‘Migrating virtual machines with Raw Device Mappings (RDMs) (1005241)VMware KB article for more info):

  1. Using vCenter Web Client you migrate Node001 to the new datastore (this will move the RDM pointers as well);
  2. Remove RDM disk from the Node002;
  3. Migrate Node002 to the new datastore;
  4. Add cluster RDM disks to Node002 using the information provided by the script.

Job done.

You may also play with where command:

# Find VM with a specific RDM disk name or LUN ID :

Get-VM | Get-View | where {$_.Config.Hardware.Device.Backing.DeviceName -match "514f0c511580009f"}

# Find VM with a RDM disk on s specific storage array – c5cc2 is the LUN ID prefix :

Get-VM | Get-View | where {$_.Config.Hardware.Device.Backing.DeviceName -match "c5cc2"}

I hope this will help.

6 comments to VMware PowerCLI script to get VM’s virtual and RDM disk information

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

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