VMware Cloud Community
sanshis
Enthusiast
Enthusiast
Jump to solution

Add new SCSI controller and new disk - powershell SDK

Hi All

I am trying to add new paravirtual disk to my VMs. there are two kinds of VMs in environment; one with Paravirtual Controller attached and others are without the controller; so my task is to attach new paravitual disk using powershell SDK.

So far i am successful with my code if controller is already present but script is failing when i try to attach the controller. with error;

RecommendDatastores : Method invocation failed because [System.Object[]] doesn't contain a method named 'RecommendDatastores'.

At C:\NodeDeployment\Inprogress\Add_newPVScsiDisk.ps1:111 char:44

+             $generatedkey = $SRM.RecommendDatastores <<<< ($storageSpec)

    + CategoryInfo          : InvalidOperation: (RecommendDatastores:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound


I know this script is not good enough to post here as its a initial draft but in attached script please help me with this part --

The Script Requires an input csv with VMname; Datastore-cluster and disksize to be attached

else {

            Write-Host "Paravirtualized SCSI Controller Not Found in $vmname.. Trying to add new scsi controller and additional Hard-disk..."

            $NewSCSIDevice = New-Object VMware.Vim.VirtualDeviceConfigSpec

            $NewSCSIDevice.operation = "add"

            $NewSCSIDevice.device = New-Object VMware.Vim.ParaVirtualSCSIController

            $NewSCSIDevice.device.key = -222

            $NewSCSIDevice.device.busNumber = ($allScSiController.BusNumber.Count)

            $NewSCSIDevice.device.sharedBus = "noSharing"

            $NewDiskDevice.device.controllerKey = -222

            $NewDiskDevice.device.unitNumber = 0

            $NewDiskDevice.device.capacityInKB = ($diskSize * (1024 * 1024))

            $storageSpec.configSpec.deviceChange += $NewDiskDevice

            $storageSpec.configSpec.deviceChange += $NewSCSIDevice

            $generatedkey = $SRM.RecommendDatastores($storageSpec)

            $key = $generatedkey.Recommendations[0].Key

            $SRM.ApplyStorageDrsRecommendation_Task($key)

}

Reply
0 Kudos
1 Solution

Accepted Solutions
sanshis
Enthusiast
Enthusiast
Jump to solution

ok i got it my self; i guess busnumber was the problem. converted it in INT working like charm.. Smiley Happy

Now i Have to work on with out storage DRS. ie. with ReconfigureVM_task method. hoping that will also work.. :smileysilly:

else {

            [int]$busnumber=$allScSiController.Count

            Write-Host "Paravirtualized SCSI Controller Not Found in $vmname.. Trying to add new scsi controller and additional Hard-disk..."

            $NewSCSIDevice = New-Object VMware.Vim.VirtualDeviceConfigSpec

            $NewSCSIDevice.operation = "add"

            $NewSCSIDevice.device = New-Object VMware.Vim.ParaVirtualSCSIController

            $NewSCSIDevice.device.key = -222

            $NewSCSIDevice.device.busNumber = $busnumber

            $NewSCSIDevice.device.sharedBus = "noSharing"

            $NewDiskDevice.device.controllerKey = -222

            $NewDiskDevice.device.unitNumber = 0

            $NewDiskDevice.device.capacityInKB = ($diskSize * (1024 * 1024))

            $storageSpec.configSpec.deviceChange += $NewDiskDevice

            $storageSpec.configSpec.deviceChange += $NewSCSIDevice

            $generatedkey = $SRM.RecommendDatastores($storageSpec)

            $key = $generatedkey.Recommendations[0].Key

            $SRM.ApplyStorageDrsRecommendation_Task($key)

        }

---

Regards
Sanshis

View solution in original post

Reply
0 Kudos
2 Replies
sanshis
Enthusiast
Enthusiast
Jump to solution

ok i got it my self; i guess busnumber was the problem. converted it in INT working like charm.. Smiley Happy

Now i Have to work on with out storage DRS. ie. with ReconfigureVM_task method. hoping that will also work.. :smileysilly:

else {

            [int]$busnumber=$allScSiController.Count

            Write-Host "Paravirtualized SCSI Controller Not Found in $vmname.. Trying to add new scsi controller and additional Hard-disk..."

            $NewSCSIDevice = New-Object VMware.Vim.VirtualDeviceConfigSpec

            $NewSCSIDevice.operation = "add"

            $NewSCSIDevice.device = New-Object VMware.Vim.ParaVirtualSCSIController

            $NewSCSIDevice.device.key = -222

            $NewSCSIDevice.device.busNumber = $busnumber

            $NewSCSIDevice.device.sharedBus = "noSharing"

            $NewDiskDevice.device.controllerKey = -222

            $NewDiskDevice.device.unitNumber = 0

            $NewDiskDevice.device.capacityInKB = ($diskSize * (1024 * 1024))

            $storageSpec.configSpec.deviceChange += $NewDiskDevice

            $storageSpec.configSpec.deviceChange += $NewSCSIDevice

            $generatedkey = $SRM.RecommendDatastores($storageSpec)

            $key = $generatedkey.Recommendations[0].Key

            $SRM.ApplyStorageDrsRecommendation_Task($key)

        }

---

Regards
Sanshis

Reply
0 Kudos
MarcoCrv
Contributor
Contributor
Jump to solution

Hello,

Would it be possibile to have the whole script? I am in kind of need of something very similar.

Thanks in advanced.

Reply
0 Kudos