Deploying Many VM’s From a Template

I recently needed to deploy a lot of VM’s for a particular scenario. They all needed to be the same but have a unique names and be on the Domain. Now there is a lot of ways to accomplish this, and one way is to build a spreadsheet and manually input all the names. It would work, but would not be the optimal way to do it as I wanted to automate as much as I could.

#Create many VM's from a Template
#Version 1.0

$vm_count = Read-Host "How many VM's would you like to deploy?"
$template = "Template"
$customspecification = "Join Domain"
$ds = "datastore"
$folder = "VM folder"
$cluster = "cluster"
$vm_prefix = "desktop-"

write-host "Starting Deployment"
1..$vm_count | foreach {
    $y="{0:D1}" -f + $_
    $vm_name = $vm_prefix + $y
    $esxi=get-cluster $cluster | get-vmhost -state connected | Get-Random
    write-host "Creationg of VM $vm_name start" 
    new-vm -name $vm_name -template $template -vmhost $esxi -datastore $ds -location $folder -oscustomizationspec $customspecification -runasync

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

Blog at

Up ↑

%d bloggers like this: