2 Replies Latest reply on Aug 4, 2017 2:43 AM by Pcliba

    Add disk on a specific virtual device node while the VM is online

    Pcliba Lurker

      Hi all,

       

      Is it possible to add a new vHDD on a specific virtual device node e.g. (0:z) while the VM is online?

      When creating a new disk with "New-HardDisk" I have no parameter for that. The disk is just added to the next free virtual device node on the SCSI controller:

       

      New-HardDisk -VM $node -CapacityGB 2 -StorageFormat thin -Controller "SCSI-Controller 0"

       

      If the VM is off, I can do it with "ExtensionData.ReconfigVM_Task" and the new specification, but I need it while the VM is online.

       

      Thanks,

      Sepp

        • 2. Re: Add disk on a specific virtual device node while the VM is online
          Pcliba Lurker

          Yes, I get the following message:

           

          Reconfigure virtual machine TestVM

          The attempted operation cannot be performed in the current state (Powered on).

           

          Thanks for the link. I'll give it a try.

          • 3. Re: Add disk on a specific virtual device node while the VM is online
            Pcliba Lurker

            Hi Luc,

             

            when trying to execute the script in the post you mentioned (Re: Script for attaching multiple existing disk to VM with specific scsi bus number and device number from CSV )

            I get the following error message:

             

            Reconfigure virtual machine

            TestVM

            Invalid configuration for device '0'.

             

            I then downloaded Onyx and received the following code:

             

            $storageSpec = New-Object VMware.Vim.StoragePlacementSpec

            $storageSpec.type = "reconfigure"

            $storageSpec.vm = New-Object VMware.Vim.ManagedObjectReference

            $storageSpec.vm.type = "VirtualMachine"

            $storageSpec.vm.Value = "vm-25596"

            $storageSpec.podSelectionSpec = New-Object VMware.Vim.StorageDrsPodSelectionSpec

            $storageSpec.podSelectionSpec.initialVmConfig = New-Object VMware.Vim.VmPodConfigForPlacement[] (1)

            $storageSpec.podSelectionSpec.initialVmConfig[0] = New-Object VMware.Vim.VmPodConfigForPlacement

            $storageSpec.podSelectionSpec.initialVmConfig[0].storagePod = New-Object VMware.Vim.ManagedObjectReference

            $storageSpec.podSelectionSpec.initialVmConfig[0].storagePod.type = "StoragePod"

            $storageSpec.podSelectionSpec.initialVmConfig[0].storagePod.Value = "group-p199"

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk = New-Object VMware.Vim.PodDiskLocator[] (1)

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0] = New-Object VMware.Vim.PodDiskLocator

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskId = -100

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.fileName = ""

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.diskMode = "persistent"

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.split = $false

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.writeThrough = $false

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.thinProvisioned = $true

            $storageSpec.podSelectionSpec.initialVmConfig[0].disk[0].diskBackingInfo.eagerlyScrub = $false

            $storageSpec.configSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

            $storageSpec.configSpec.changeVersion = "2017-08-07T12:03:48.505627Z"

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

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

            $storageSpec.configSpec.deviceChange[0].operation = "add"

            $storageSpec.configSpec.deviceChange[0].fileOperation = "create"

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

            $storageSpec.configSpec.deviceChange[0].device.key = -100

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

            $storageSpec.configSpec.deviceChange[0].device.backing.fileName = ""

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

            $storageSpec.configSpec.deviceChange[0].device.backing.split = $false

            $storageSpec.configSpec.deviceChange[0].device.backing.writeThrough = $false

            $storageSpec.configSpec.deviceChange[0].device.backing.thinProvisioned = $true

            $storageSpec.configSpec.deviceChange[0].device.backing.eagerlyScrub = $false

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

            $storageSpec.configSpec.deviceChange[0].device.connectable.startConnected = $true

            $storageSpec.configSpec.deviceChange[0].device.connectable.allowGuestControl = $false

            $storageSpec.configSpec.deviceChange[0].device.connectable.connected = $true

            $storageSpec.configSpec.deviceChange[0].device.controllerKey = 1000

            $storageSpec.configSpec.deviceChange[0].device.unitNumber = 14

            $storageSpec.configSpec.deviceChange[0].device.capacityInKB = 5242880

            $storageSpec.configSpec.vAppConfig = New-Object VMware.Vim.VmConfigSpec

            $storageSpec.configSpec.vAppConfig.product = New-Object VMware.Vim.VAppProductSpec[] (1)

            $storageSpec.configSpec.vAppConfig.product[0] = New-Object VMware.Vim.VAppProductSpec

            $storageSpec.configSpec.vAppConfig.product[0].operation = "edit"

            $storageSpec.configSpec.vAppConfig.product[0].info = New-Object VMware.Vim.VAppProductInfo

            $storageSpec.configSpec.vAppConfig.product[0].info.key = 0

            $storageSpec.configSpec.vAppConfig.product[0].info.classId = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.instanceId = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.name = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.vendor = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.version = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.fullVersion = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.vendorUrl = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.productUrl = ""

            $storageSpec.configSpec.vAppConfig.product[0].info.appUrl = ""

             

             

            $_this = Get-View -Id 'StorageResourceManager-StorageResourceManager'

            $_this.RecommendDatastores($storageSpec)

            How can I execute this code in powercli?

            I tried to change it into the form of your script but It didn't work.

            • 4. Re: Add disk on a specific virtual device node while the VM is online
              LucD Guru

              You can't convert the result from Onyx as-is.

              Output from Onyx should be considered as a closer look at how the client code is performing the action.

               

              The code you got from Onyx is using the RecommendDatastores method, that is available when you have a DatastoreCluster.

              My script you linked to is not taking DatastoreClusters into account.

              You would need to rewrite my script to use this RecommendDatastores method.

              The trick is in assigning the VMDK's UnitNumber and the eventual Controller's BusNumber with the desired values.