Deploy Multiple VM's with PowerCLI and a vCenter Custom Spec.


This blog post assumes you have a working vCenter server with at least one host, datastore, network etc...requirements are listed below: 

What is required: 

  • Admin access to a running vCenter environment, preferably a lab!
  • Powershell v5 and PowerCLI 6.5.
  • A premade template, EG Windows Server 2016.
  • A vCenter custom spec for the configuration of guest operating systems.

Details of my lab are below. I am fortunate to have access to real servers where I work but a computer with enough disk space and maybe 16gb of ram will suffice. You may not be able to run as much simultaneously.

My Lab:
Dell PowerEdge server 128GB RAM
VMware Workstation Pro 12
3 Virtual Machines located inside VMware Workstation. 
2 ESXi Servers, 1 Active Directory domain controller.
My vCenter server appliance (VCSA.contoso.com) is running on one of my virtual ESXi servers.


The Environment:

Active Directory and DNS: 10.1.1.1
DHCP provided by VMware workstation network manager.
vCenter Server Appliance 10.1.1.10
ESXi Host 1 - 10.1.1.11
ESXi Host 2 - 10.1.1.12


The Custom Spec:

The VM custom spec has several customisations including adding to my domain, a product key for windows and also network settings. Make use of custom specs for deployment automation.

The script:

You can also replace the array with a text file or CSV file that contains the names of your virtual machines. If you want to deploy one machine at a time, remove the -RunAsync parameter from the bottom of the script.


 1

32
# Imports the PowerCLI module and logs into vCenter server.
Import-Module VMware.VimAutomation.Core
Connect-VIServer YOUR_VCENTER_SERVER_NAME


# Text/CSV file with Names or an Array with names.
$vms = "MYVM01","MYVM03","MYVM04"

# Edit these Variables for your own environment.
$VMHost = "10.1.1.11"
$VMName = $vm
$Template = "THIS_IS_YOUR_TEMPLATE_NAME"
$Datastore = "A_DATASTORE_NAME"
$Location = "A VM FOLDER"
$VMSpec = "CUSTOM SPEC NAME"
$VMNotes = Get-date
$Notes = $VMNotes

# For every VM in the array above, it will run this script to deploy them.
foreach ($vm in $vms)
    {
    New-VM -Name $vm `
    -Template $Template `
    -VMHost $VMHost `
    -Datastore $Datastore `
    -Location $Location `
    -Notes $VMNotes `
    -OSCustomizationSpec $VMSpec `
    -RunAsync
    }

   

Comments

Popular posts from this blog

VM Tools fail to upgrade with vix error 21007