VMware Cloud Community
stromcooper
Contributor
Contributor
Jump to solution

Any way to set Virtual Device Node / SCSI Disk ID?

Is there any way to set, via PowerCLI, the virtual device node / SCSI disk ID of a specific VM hard disk?  We need to pin a large VM's disks to specific controllers and disk IDs to ensure consistency across multiple deployments.  Getting them on the specific controller was easy, but I have not been able to find a way to set the disk ID.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, stromcooper-

You can use the ReconfigVM() method of a VirtualMachine object to change this.  It is the UnitNumber property of the VirtualDisk, and you create a couple of ConfigSpec objects to make the change, like:

## the VM on which to change a disk's SCSI ID
$strVMToUpdate = "someVM"
## get the VM
$vmToUpdate = Get-VM $strVMToUpdate
## get the hard disk to change; assumes it is called "Hard disk 2" here
$hdskToChange = Get-HardDisk -VM $vmToUpdate -Name "Hard disk 2"

## create a new VirtualMachineConfigSpec, with which to make the change to the VM's disk
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
## create a new VirtualDeviceConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = "edit"
## populate the "device" property with the existing info from the hard disk to change
$spec.deviceChange[0].device = $hdskToChange.ExtensionData
## then, change the second part of the SCSI ID (the UnitNumber)
$spec.deviceChange[0].device.unitNumber = 8
## reconfig the VM with the updated ConfigSpec (VM must be powered off)
$vmToUpdate.ExtensionData.ReconfigVM_Task($spec)

The line where it is setting ...unitNumber to "8" is where you would put your desired ID.  This bit of code keeps the VirtualDisk on the same SCSI controller on which it already resides.  Note:  the VM needs to be powered down for the reconfig task.

How does that do for you?

View solution in original post

0 Kudos
3 Replies
mattboren
Expert
Expert
Jump to solution

Hello, stromcooper-

You can use the ReconfigVM() method of a VirtualMachine object to change this.  It is the UnitNumber property of the VirtualDisk, and you create a couple of ConfigSpec objects to make the change, like:

## the VM on which to change a disk's SCSI ID
$strVMToUpdate = "someVM"
## get the VM
$vmToUpdate = Get-VM $strVMToUpdate
## get the hard disk to change; assumes it is called "Hard disk 2" here
$hdskToChange = Get-HardDisk -VM $vmToUpdate -Name "Hard disk 2"

## create a new VirtualMachineConfigSpec, with which to make the change to the VM's disk
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
## create a new VirtualDeviceConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = "edit"
## populate the "device" property with the existing info from the hard disk to change
$spec.deviceChange[0].device = $hdskToChange.ExtensionData
## then, change the second part of the SCSI ID (the UnitNumber)
$spec.deviceChange[0].device.unitNumber = 8
## reconfig the VM with the updated ConfigSpec (VM must be powered off)
$vmToUpdate.ExtensionData.ReconfigVM_Task($spec)

The line where it is setting ...unitNumber to "8" is where you would put your desired ID.  This bit of code keeps the VirtualDisk on the same SCSI controller on which it already resides.  Note:  the VM needs to be powered down for the reconfig task.

How does that do for you?

0 Kudos
stromcooper
Contributor
Contributor
Jump to solution

Worked brilliantly.  Thank you sir!

0 Kudos
HazeB
Contributor
Contributor
Jump to solution

Worked as a charm! Thanks!

0 Kudos