Skip to content

Instantly share code, notes, and snippets.

@asvignesh
Created January 2, 2019 17:23
Show Gist options
  • Save asvignesh/2e6c7f4e062820a2655487be48f46b95 to your computer and use it in GitHub Desktop.
Save asvignesh/2e6c7f4e062820a2655487be48f46b95 to your computer and use it in GitHub Desktop.
Deploy multiple virtual machines from template using powercli
# Specify vCenter Server, vCenter Server username and vCenter Server user password
$vCenter="lab.asvignesh.in"
$vCenterUser="[email protected]"
$vCenterPassword="secretPassword"
#
# Specify number of VMs
$vm_count = "100"
#
# Specify the template
$tempate = "W2k12"
#
# Specify the VM image Customization Specification
$customspecification="AD-Customization"
#
# Specify the datastore
$ds = "vignesh-ds-1"
#
$host = "esxi1.asvignesh.in"
# Specify Virtual Machine & Templates folder
$Folder = "QA"
#
# Specify the VM name
$VM_prefix = "asvignesh-"
#
# End of user input parameters
#
write-host "Connecting to vCenter Server $vCenter" -foreground green
Connect-viserver $vCenter -user $vCenterUser -password $vCenterPassword -WarningAction 0
1..$vm_count | foreach {
$y="{0:D1}" -f + $_
$VM_name= $VM_prefix + $y
write-host "Creation of VM $VM_name initiated" -foreground green
New-VM -Name $VM_Name -Template $tempate -VMHost $host -Datastore $ds -Location $Folder -OSCustomizationSpec $customspecification -RunAsync
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment