Deploy Multiple VM’s using PowerCLI and VMware Template

I wanted to create a few different VM’s so I can test a VMware daily report script. This can be done using deploy VM from template using the vSphere web client but this can take a long time. I decided to write a quick PowerShell script to deploy the VM’s use PowerCLI. I first ran Get-Template to get the name of the template I wanted to use.


I decided to use numerical numbering for my VM’s . So I used a while loop so that it would start at 1 and I added to the $i variable at the end of the loop so it would run until it hit 10. I used the variable $DS to get the datastores and piped that to get-random so the VM’s would be spread across both datastores. If you want to select just one datastore just remove the $DS variable and change the ($DS | Get-Random) to the datastore you want to select.

$DS = Get-Datastore -Name Local*
$i = 1
while ($i -le 10){
New-VM -Name “Linux-VM$i” -Template “Linux-VM_Template” -Datastore ($DS | Get-Random) -VMHost “Esxihost to deploy to”
Deploy OVF template

I then used the below command to get the list of VM’s and their datastores.

Get-VM -Name Linux-VM* | Select Name,@{N=”Datastore”;E={(Get-Datastore -Id $_.DatastoreIdList)}}



2 thoughts on “Deploy Multiple VM’s using PowerCLI and VMware Template

  1. Hello,
    I need some help about using the command New-Vm.
    On my cluster, I have several templates when I did get-template.
    So when I tried to create new-vm with template parameter, I got this error message:
    New-VM : 24/06/2019 11:15:20 New-VM The specified parameter ‘Template’
    expects a single value, but your name criteria ‘Template-W2K19’ corresponds to
    multiple values.

    Thanks for your help


  2. Hi David

    Are you using the above script if not can you post the command /script you are using by the looks of the error the command has multiple value or possible multiple connection to vCenter and the New-VM can only select a single value.



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 )

Google photo

You are commenting using your Google 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