Hi!
I have Vsphere 6.
How i can add new disk and set Hard Disk MW flag on Powered On VM?
Not sure where that KB says that the VM needs to be powered off.
In any case, with the following, I can add a RDM HD with MultiWriter set while the VM is powered on.
$diskNAA = 'naa.600031234dc75adc8a8545aa4f696c11'
$vm = Get-VM -Name $vmName
$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'
$scsiBus = $scsi.ExtensionData.BusNumber
$scsiKey = $scsi.Key
$unitNr = Get-HardDisk -VM $vm | %{$_.ExtensionData.UnitNumber} |
Measure-Object -Maximum | select -ExpandProperty Maximum
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$disk = New-Object VMware.Vim.VirtualDisk
$back = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo
$back.CompatibilityMode = 'physicalMode'
$back.FileName = ''
$back.DiskMode = [VMware.Vim.VirtualDiskMode]::independent_persistent
$back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter
$back.DeviceName = "/vmfs/devices/disks/$($diskNAA)"
$disk.Key = -100
$disk.ControllerKey = $scsiKey
$disk.UnitNumber = $unitNr + 1
$disk.Backing = $back
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add
$dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create
$dev.Device = $disk
$spec.DeviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at Re: RDM Disk with Multiwriter
If you only want to do this on one VM, you would only need the 1st part of the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think that you cannot add/set multiwriter flag on powered on VM.
Take a lok on this KB:
https://kb.vmware.com/s/article/1034165
Additional, i cannot find KB but we need to disable CBT for shared disks. I will ask my colleagues to find out why we had to do tath
Edited:
In KB you can find that CBT in not supported.
Disable CBT on multi writer disks:
Not sure where that KB says that the VM needs to be powered off.
In any case, with the following, I can add a RDM HD with MultiWriter set while the VM is powered on.
$diskNAA = 'naa.600031234dc75adc8a8545aa4f696c11'
$vm = Get-VM -Name $vmName
$scsi = Get-ScsiController -VM $vm -Name 'SCSI controller 0'
$scsiBus = $scsi.ExtensionData.BusNumber
$scsiKey = $scsi.Key
$unitNr = Get-HardDisk -VM $vm | %{$_.ExtensionData.UnitNumber} |
Measure-Object -Maximum | select -ExpandProperty Maximum
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$disk = New-Object VMware.Vim.VirtualDisk
$back = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo
$back.CompatibilityMode = 'physicalMode'
$back.FileName = ''
$back.DiskMode = [VMware.Vim.VirtualDiskMode]::independent_persistent
$back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter
$back.DeviceName = "/vmfs/devices/disks/$($diskNAA)"
$disk.Key = -100
$disk.ControllerKey = $scsiKey
$disk.UnitNumber = $unitNr + 1
$disk.Backing = $back
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add
$dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create
$dev.Device = $disk
$spec.DeviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD you are right.
Info about powering off VM was related to older ESXi versions. My fault.
Thanks for reply!
Thanks LucD!
I found that the task is larger than previously thought. That's why I wrote in an old topic. Now I need to add a shared disk to 2 nodes. I have a piece of code that works fine and suits me. This part adds a zeroed disk to the specified controller. This controller has the bus sharing physical property. How do I further identify the filepath variable to connect the disk to the second node? A prerequisite is that the disks on all nodes have the same controller number and bus number.
$vm = Get-VM -Name Test-MW-01
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$scsiKey = -100
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add
$controller = New-Object VMware.Vim.VirtualLsiLogicSASController
$controller.Key = $scsiKey
$controller.BusNumber = 1 #Conroller number
$controller.SharedBus = "physical"
$dev.Device = $controller
$spec.DeviceChange += $dev$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$disk = New-Object VMware.Vim.VirtualDisk
$back = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
$back.FileName = "[$($dsName)]"
$back.ThinProvisioned = $false
$back.DiskMode = 'persistent'
$back.EagerlyScrub = $true
$back.Sharing = [VMware.Vim.VirtualDiskSharing]::sharingMultiWriter
$disk.Key = -100
$disk.ControllerKey = $scsiKey
$disk.CapacityInKB = $diskSizeGB*1GB/1KB
$disk.UnitNumber = 0
$disk.Backing = $back
$dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::add
$dev.FileOperation = [VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create
$dev.Device = $disk
$spec.DeviceChange += $dev$vm.ExtensionData.ReconfigVM($spec)
After you attached the RDM in the correct way to the first VM, you can fetch the info.
And then use that info to attach the harddisk to the 2nd VM.
$vm = Get-VM -Name $vmName
$hd = Get-HardDisk -VM $vm | where{$_.DiskType -eq 'RawPhysical'}
$fileName = $hd.ExtensionData.Backing.FileName
$unitNumber = $hd.ExtensionData.UnitNumber
$ctrl = $vm.ExtensionData.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}
$busNumber = $ctrlBusNumber
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference