VMware Cloud Community
A_S
Enthusiast
Enthusiast

How to add extra vmdisk if more than 1 SCSI controller and more than 6 disks connected...

Hi,

I would like to script the (extra) disk addition to VMs. The only available parameters are VM name, Size of disk in GB, and DatastoreName where to create it.

The challenge (i guess need to do this in SDK way) is how to determine the SCSI controller key and unitnumber (if there are more than 1 VMdisk attached to controller or more than 1 SCSI controller)

Playing with onyx but i can't find the way to do that...

   

'Pseudocode for  $vm.ReconfigVM($spec).

#Check 1 :

If only one SCSI controller found then

     Add extra VMdisk  (i guess last found highestunitnumber + 1) and controllerkey of this SCSI controller

     'Less than 6 disks or more than 8 and less than 14 disks

     'SCSI0:0-SCSI0:6 ... 'SCSI0:8-SCSI0:14

end if

# Check 2

if more than 1 scsi controller found

     Add extra VMdisk to highest SCSI controller key

    'that can handle also the rules   less than 6 disks or more than 8 and less than 14 disks

    ''SCSI1:0-SCSI1:6 ... 'SCSI1:8-SCSI1:14 until  SCSI3:0-SCSI1:6 ... 'SCSI1:8-SCSI1:14

end if

# snippet of onyx code that need to be replaced...

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

$spec.deviceChange[0].operation = "add"

$spec.deviceChange[0].fileOperation = "create"

$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualDisk

$spec.deviceChange[0].device.key = -100

$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.deviceChange[0].device.backing.fileName = "[MyOtherDatastore_001]"

$spec.deviceChange[0].device.backing.diskMode = "persistent"

$spec.deviceChange[0].device.backing.split = $false

$spec.deviceChange[0].device.backing.writeThrough = $false

$spec.deviceChange[0].device.backing.thinProvisioned = $false

$spec.deviceChange[0].device.backing.eagerlyScrub = $false

$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$spec.deviceChange[0].device.connectable.startConnected = $true

$spec.deviceChange[0].device.connectable.allowGuestControl = $false

$spec.deviceChange[0].device.connectable.connected = $true

$spec.deviceChange[0].device.controllerKey = 1000          # How to fill this one by following the rules as described in pseudocode?

$spec.deviceChange[0].device.unitNumber = 10                # How to fill this one by following the rules as described in pseudocode?

$spec.deviceChange[0].device.capacityInKB = 2097152

$_this = (get-VM -Name MyVMname).ExtensionData

$_this.ReconfigVM_Task($spec)

Does someone have any tips how to do this?

thanks in advance.

$_this = Get-View -Id
'VirtualMachine-vm-821'

$_this.ReconfigVM_Task($spec)

0 Kudos
1 Reply
sanshis
Enthusiast
Enthusiast

Check following link -- though this is my question regarding adding new controller but i you will still get your answers. ( i am counting on devices.)
Add new SCSI controller and new disk - powershell SDK

0 Kudos