Hi all,
I have been tasked with migrating a 4 digit number of VMs to new data stores. A couple of hundred of these have anywhere from 2 to 40+ RDMs shared between 2 VMs. The migration requires the RDMs to be unmapped from 1 node, migrated and then be remapped since the migration updates the pointers.
Now, as of today the admins copy the info form the vSphere client and make a text document to keep track.
I found this little gem, and run PowerCLI to extract the info:
$DiskInfo= @()
foreach ($VMview in Get-VM node01 | 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:\temp\diskinfo.csv'
Now, the next logical step would be to take this info, import the .csv and apply this info to node02?
I came across LucD's code that does some of it, but requires that you know the file path of each RDM:
$vm1 = Get-VM -Name node01
$vm2 = Get-VM -Name node02
$DeviceName = "/vmfs/devices/disks/naa.600507680180701ed00000000000124"
$hd1 = New-HardDisk -VM $vm1 -DeviceName $DeviceName -DiskType RawVirtual
$ctrl1 = New-ScsiController -HardDisk $hd -BusSharingMode Virtual -Type VirtualLsiLogicSAS
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device += $ctrl1.ExtensionData
$spec.deviceChange[0].device.Key = -101
$spec.deviceChange[0].operation = "add"
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].device += $hd1.ExtensionData
$spec.deviceChange[1].device.Key = -102
$spec.deviceChange[1].device.ControllerKey = -101
$spec.deviceChange[1].operation = "add"
$vm2.ExtensionData.ReconfigVM($spec)
I there an easy way to do this?
Someone has probably done this already, I just can't find it. Probably me searching skills that suck.