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 and a CSV file. First we need to get the template that are available in vCenter server.

Connect to to vCenters server using PowerCLI and then run Get-Template to list all templates and then copy the name of the template. This will be added to the csv file.

This image has an empty alt attribute; its file name is image-82.png

Since I am going to be using a csv file to create the VM’s this needs to be created with headings that will be called in the script.

Below are the heading I used in the csv, these can either be used as is or the script can be updated using different headings.

NameDatastoreTemplateCluster

Below is the completed csv file I will be using.

Below is the script I used you just need to update the $vms variable with the path that has the csv file.

$vms = Import-Csv -Path D:\Scripts\VMware\Deploy_VMs\Deploy_VMs.csv
foreach ($vm in $vms) {
Write-Warning "Creating $($vm.Name) in $($vm.cluster)"
New-VM -Name $vm.Name -Datastore $vm.Datastore -Template $vm.Template  -ResourcePool $vm.Cluster
}

To confirm the VM’s are being created we can check vCenter Server for running tasks.

The deployment can take awhile depending on the size of the template.

I then used the below command to get the list of VM’s and their datastores just to confirm all VM’s have been created and are in the correct datastore.

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

This is just a quick example of deploying a VM using a template

4 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

    Like

  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.

    Thanks

    Like

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s