Create VirtualMachine using template and customize OS with custom data for multiple VirtualMachine using PowerCLI
search cancel

Create VirtualMachine using template and customize OS with custom data for multiple VirtualMachine using PowerCLI

book

Article ID: 372734

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

To deploy multiple virtual Machine using powercli use below script to avoid manual steps and repetitive task: 

 

Resolution

Avoid manual intervention to create multiple VMs using Template with custom property.

 

Connect-VIServer -Server XXXXX -User xxxxx -Password xxxxx

$VirtualMachinesCSV = Import-Csv -path "E:\M_VMcreation\csvfilename.csv"
foreach($VM in $VirtualMachinesCSV){
write-host $VM.Name
Get-OSCustomizationSpec -Name $VM.CustomSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UsestaticIP -IPAddress $VM.Ipaddress -Dns "xxx.xxx.xx.xx","xx.xx.xx.x" -SubnetMask "xx.xx.xx.xx" -DefaultGateway $VM.Gateway 
New-VM -Name $VM.Name -Template $VM.Template -Host $VM.DestinationHost -Datastore $VM.Datastore  -OSCustomizationSpec $VM.CustomSpec 
Set-VM -VM $VM.Name -NumCpu $VM.NumCpu -MemoryMB $VM.MemoryMB -Confirm:$false   
Get-VM -Name $VM.Name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $VM.vPGnetwork -Type VMXNET3 -Confirm:$false
Get-VM $VM.Name | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected:$true -Confirm:$false
Start-VM -VM $VM.Name -Confirm:$false -RunAsync
}

Note: InputVM.csv is sample for custom field is attached. 

Attachments

InputVM.csv get_app