Automation

 View Only

 How to Deploy a VM from a Template and Adjust Hardware Configurations with PowerCLI

Luca Lotter's profile image
Luca Lotter posted Aug 19, 2024 07:28 AM

I'm facing some confusion with PowerCLI regarding the creation of virtual machines from templates. Specifically, I'm having trouble understanding why I can't modify hardware settings (like CPU cores or memory) in the same step when creating a VM from a template using PowerCLI. This adjustment seems to be straightforward in the vCenter GUI, but I'm hitting a roadblock with PowerCLI.

In the vCenter GUI, you can easily customize hardware settings during the VM creation process from a template. However, when using the New-VM cmdlet in PowerCLI, there doesn't seem to be a way to adjust these settings directly at the time of creation. 

The official Broadcom documentation specifies that when using the -Template parameter, you cannot customize the hardware settings directly. This is frustrating because, when using -OSCustomizationSpec to customize NIC settings, I need to create multiple network adapters to ensure that the NIC settings are properly applied. I want to avoid modifying the template itself for every change, as that could lead to inconsistencies or unintended alterations. If i do it afterwards its messy.

Has anyone found a solution or workaround for this issue? How can I create a VM from a template and adjust its hardware settings in one go using PowerCLI? Any insights or examples would be greatly appreciated!

Todd Bertschi's profile image
Todd Bertschi

I just create the VM from the template and not power it on. From there I can change the hardware specs with Set-VM. I've gone through and added NICs and adjusted Memory, Disk and CPU per system type. Once that's done, I power on the system and use the Invoke-VMScript to change network settings (setting static IP's) or anything else I need like installing security tools. Customizations are nice, but I've found them limiting so I prefer to just hit the OS and make changes I need although I'm leaning more towards Desired State Configuration for changes made after the VM get's powered on.

Peace

linhtm27's profile image
linhtm27

Invoke-VMScript is not good choice because it requires user/password when login to GuestOS. Best choice is use Customization Script for Linux or Command to run Once for Windows instead of Invoke-VMScrip.

So, we can also combine with OSCustomizationSpec to build a complete new VM