Deploy a VM from template with PowerCLI

Now that I have a small VM for my test lab, I converted it to a template and looked for a cool way to deploy several VMs from this template with PowerCLI. Turns out it’s actually really easy, anti-climactic, even. The good folks over at have an excellent tutorial on this topic. Alan Renouf (Twitter @alanrenouf) was the first to comment on their blogpost. He included a nice for loop to replace a single line for each VM deployment. I incorporated Alan’s suggestion as well as a few options from the PowerCLI New-VM cmdlet reference page, like adding the VM to a resource pool and then powering on the VM.

Here’s the code:

1..2 | Foreach {
New-vm -vmhost esx01.testlab.local -ResourcePool 2-Low -Name linux$_ -Template linux_template -Datastore data1 | start-vm
3..4 | Foreach {
New-vm -vmhost esx02.testlab.local -ResourcePool 1-Medium -Name linux$_ -Template linux_template -Datastore data1 | start-vm

A nice progress bar is shown from within the CLI.

And you can watch the progress as VMs start to appear in the inventory and power on automatically.

In the end, this is what it looks like



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s