Hi
I am trying to create a new harddisk to my VM. When I execute the command I get an error.
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vm "HORSE" | new-harddisk -capacitykb 10240
New-HardDisk : 03-06-2008 21:54:47 New-HardDisk No free LSI nodes
At line:1 char:32
+ get-vm "HORSE" | new-harddisk <<<< -capacitykb 10240
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows>
It is a VM without a SCSI controller, an I guess it tells me that. Then my question is: How do I add a SCSI controller??
Regards
Claus
The function below adds a BusLogic SCSI controller to a guest.
The prerequisite for the function to work correctly is that there are no devices with the same "key" defined on the guest.
The function could be elaborated with a test that loops through the current devices and checks if the key is free.
Something like the functions I showed in
function add-SCSIController { param($VMname) $vm = Get-View (Get-VM $VMname).ID $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.deviceChange = @() $spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.deviceChange[0].device = New-Object VMware.Vim.VirtualBusLogicController $spec.deviceChange[0].device.busNumber = 0 $spec.deviceChange[0].device.ControllerKey = 100 $spec.deviceChange[0].device.DeviceInfo = New-Object VMware.Vim.Description $spec.deviceChange[0].device.DeviceInfo.label = "SCSI Controller 0" $spec.deviceChange[0].device.DeviceInfo.summary = "BusLogic" $spec.deviceChange[0].device.hotAddRemove = $TRUE $spec.deviceChange[0].device.key = 1000 $spec.deviceChange[0].device.scsiCtlrUnitNumber = 7 $spec.deviceChange[0].device.sharedBus = "noSharing" $spec.deviceChange[0].operation = "add" $vm.ReconfigVM_Task($spec) } Add-SCSIController("HORSE") Get-VM "HORSE" | New-HardDisk -CapacityKB 10240
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The function below adds a BusLogic SCSI controller to a guest.
The prerequisite for the function to work correctly is that there are no devices with the same "key" defined on the guest.
The function could be elaborated with a test that loops through the current devices and checks if the key is free.
Something like the functions I showed in
function add-SCSIController { param($VMname) $vm = Get-View (Get-VM $VMname).ID $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.deviceChange = @() $spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.deviceChange[0].device = New-Object VMware.Vim.VirtualBusLogicController $spec.deviceChange[0].device.busNumber = 0 $spec.deviceChange[0].device.ControllerKey = 100 $spec.deviceChange[0].device.DeviceInfo = New-Object VMware.Vim.Description $spec.deviceChange[0].device.DeviceInfo.label = "SCSI Controller 0" $spec.deviceChange[0].device.DeviceInfo.summary = "BusLogic" $spec.deviceChange[0].device.hotAddRemove = $TRUE $spec.deviceChange[0].device.key = 1000 $spec.deviceChange[0].device.scsiCtlrUnitNumber = 7 $spec.deviceChange[0].device.sharedBus = "noSharing" $spec.deviceChange[0].operation = "add" $vm.ReconfigVM_Task($spec) } Add-SCSIController("HORSE") Get-VM "HORSE" | New-HardDisk -CapacityKB 10240
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That did the trick. Thanks for the nice script. (I modified it to add a LSI scsi adapter in no time)
Regards
Claus
Hi Luc,
we are trying to create a VM with OS drive on an LSI controller and Data drive on a PVSCI controller. We have figured out how to create the two controllers, but I cannot figure out how to create a “Data” drive on SCSI bus 1, instead of the default 0. Can you advise as to create a new hard drive but at SCSI ID 1:0 instead of 0:1 so it is connected to the PVSCI controller instead of the boot LSI controller?
function add-PVSCISCSIController {
param($GuestVM)
$vm = Get-View (Get-VM $GuestVM).ID
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = @()
$spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device = New-Object VMware.Vim.ParaVirtualSCSIController
$spec.deviceChange[0].device.busNumber = 1
$spec.deviceChange[0].device.ControllerKey = 100
$spec.deviceChange[0].device.DeviceInfo = New-Object VMware.Vim.Description
$spec.deviceChange[0].device.DeviceInfo.label = “SCSI Controller 1″
$spec.deviceChange[0].device.DeviceInfo.summary = “Paravirtual”
$spec.deviceChange[0].device.hotAddRemove = $FALSE
$spec.deviceChange[0].device.key = 1000
$spec.deviceChange[0].device.scsiCtlrUnitNumber = 7
$spec.deviceChange[0].device.sharedBus = “noSharing”
$spec.deviceChange[0].operation = “add”
$vm.ReconfigVM_Task($spec)
}
add-PVSCISCSIController($VMName)
New-HardDisk -CapacityKB $2K8DataDriveSize -Datastore $VMDatastore -VM $VMName
In the current release the New-Harddisk cmdlet doesn't allow you to specify a specific controller.
Have look at my Add-HD function in ?
In that function I show how to add a hard disks to a specific controller.
In that thread it was done for an existing hard disk but you can easily change the function to create a new hard disk.
The trick is first obtaining the controller's Key property and then specifying that Key in the controllerKey property of the new hard disk.
Let me know if this is enough to complete the function.
If not, I can provide you a sample script.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot Luc. I was playing around with Onyx as well after posting and that was really helpful. That is a really cool tool. Anyway, thanks a lot for the assist. I am a big fan of the blog and your VMware Communities postings. They have been very helpful. You can remove my question from John Cousens from your blog home page. I didn't mean to post the question there. Sorry. Have a great weekend.
Regards,
John Cousens
Onyx is indeed a great tool but use it with caution. See also Carter's "Don't get burned" slide.
Btw the slides for Carter's PEX session on Onyx can be found here.
The comments are removed.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference