vCenter

 View Only

Adding SCSI Controller per Script

  • 1.  Adding SCSI Controller per Script

    Posted Nov 24, 2016 11:45 AM

    Hi together,

    i am writing a script to add snapshotdevices to an existing and running virtual machine. These snapshotdevices are just a view on a SAN snapshots of datastores.

    The target virtual machine is a kind of backup proxy and due to internal best practices, i would like to add as much as possible pvscsi adapters.

    At first, i tried the following command with the message, that the new controller could only been added, when the vm is powered off.

         $newhdd = new-harddisk -vm $tgtvm -diskpath $sourcefolder

         new-scsicontroller -harddisk $newhdd -type paravirtual

    I understand what the problemis. You cannot change the scsi bus of an hdd, while the VM is poweredon.

    The second try was like following, with the same message:

    new-harddisk -vm $tgtvm -diskpath $sourcefolder | new-scsicontroller -type paravirtual

    Because the existing virtual disk has been added to the VM, i expect, it is the same way the two ways are getting handled.

    First add the vmdk.

    Second add a new controller and remap the added vmdks.

    So i tried to get the commands using onyx and this is what i get back:

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.changeVersion = "2016-11-23T14:15:49.149252Z"

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

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

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

    $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 = "[snap-11e0a658-tdsvi02_nss4141a1v_253] syscopy-target/syscopy-source.vmdk"

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

    $spec.deviceChange[0].device.backing.thinProvisioned = $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 = -101

    $spec.deviceChange[0].device.unitNumber = 1

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

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

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

    $spec.deviceChange[1].device = New-Object VMware.Vim.ParaVirtualSCSIController

    $spec.deviceChange[1].device.key = -101

    $spec.deviceChange[1].device.controllerKey = 100

    $spec.deviceChange[1].device.busNumber = 1

    $spec.deviceChange[1].device.sharedBus = "noSharing"

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

    $_this.ReconfigVM_Task($spec)


    Here i receive the message that there are some concurrent tasks beeing executet by an other user.

    After this i have rebooted the vCenter and ESXi Hosts so cancel stuck tasks, but that did not fix it.

    I patched my vCenter and ESXi Servers to the newest Version of 5.5 without solving the problem.

    Any ideas how to fix it or are there other ways to add the controller?