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.

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.
Name | Datastore | Template | Cluster |
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
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
LikeLike
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
LikeLike
Hi SleepyAdmin,
Can this script be updated to add ability to customise RAM/CPU and secondary hard drive at all?
Thanks
LikeLike
Hi
It can, will see if I can get some time to update and test the script. Will update my github when its ready.
LikeLike