VMware Cloud Community
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Adding multiple disks during VM creation

I have been working on a script to create VMs in bulk, with the intent of having a front-end GUI for the script so lower-level techs can create VMs. The script and its associated GUI are working, so I have been attempting to add in some "nice to have features". One said feature is creating a second or third vDisk, but this has proven problematic. In essence the GUI exports all content to a csv and then the script imports this to create VMs. The code I am using for the disk creation is as follows:

#region Configure vDisks

   If (!($oVM.HDD2Size) -eq '')) {

        If (!($oVM.HDD2Format -eq '')) {

             New-HardDisk -VM $oVM.Name -CapacityGB $oVM.HDD2Size

        }else{

             New-HardDisk -VM $oVM.Name -CapacityGB $oVM.HDD2Size -StorageFormat $oVM.HDD2Format

        }

   }

Unfortunately the disk is never created. I can tell that I am hitting the If statement, and can see which sub-statement is being selected, but the New-HardDisk is never processed. I have tried moving the disk creation to the very end, well after the VM is created, moved to the appropriate folder, network is configured, etc. etc., but still no joy. If I finish the PowerCLI session and then run the same code above, the disk is created no problem. I am just curious is this expected behavior? Should I not be able to create a second, third, fourth disk at the same time I create my VM?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No, that is not expected behaviour.

I assume the New-VM cmdlet has already executed at this point, has it?
Does a Get-VM return an object before these Ifs?
Are you running the New-VM with -RunAsync switch?
Did you already try adding the -Verbose switch on the New-HardDisk cmdlets?

Update: another option, on the New-VM, you can specify multiple values on the DiskGB parameter.

One value for each harddisk, an array.
You could fill up that array instead of calling extra New-Hard


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

No, that is not expected behaviour.

I assume the New-VM cmdlet has already executed at this point, has it?
Does a Get-VM return an object before these Ifs?
Are you running the New-VM with -RunAsync switch?
Did you already try adding the -Verbose switch on the New-HardDisk cmdlets?

Update: another option, on the New-VM, you can specify multiple values on the DiskGB parameter.

One value for each harddisk, an array.
You could fill up that array instead of calling extra New-Hard


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast
Jump to solution

It turned out to be a stupid mistake; the way the GUI was loading the storage format into the spreadsheet did not exactly match the parameter wording in the New-HardDisk call. Thanks again for the nudge.

The idea of doing an array with the DiskGB parameter is interesting to me; might simplify things a bit. Can that be done if you are creating from an OS Customization and only want to specify second, and possibly third, disks? I could not find a way to leave the OS drive as it is in the customization but set other disks to passed values. If you have an example I could review that would be awesome.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid that the DiskGB and OSCustomizationSpec parameters belong to two different parametersets, so no, you can't combine them.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Thanks. The New-HardDisk calls are working; that is the most important part.

0 Kudos