CSV format


wKioL1l3CR3zZ1WoAAAjTdTcIco471.png


PowerCLI script


#PowerCLI to create multiple VMs from template

Add-PSSnapin vmWARE.VimAutomation.Core
$vc="vcname"
connect-viserver $vc


#Import VM information 
$VMs = Import-CSV "C:\NewVMs.csv"
 
foreach ($vm in $vms){
#Assign Variables
$VMName = $vm.Name
$Template = $vm.Template
$Cluster = $vm.Cluster
$Datastore = $vm.Datastore
$Custom = $vm.Customization
$vCPU = $vm.vCPU
$Memory = $vm.Memory
$Location = $vm.Location
$ESXi = $vm.ESXi
$Network = $vm.Network


#Create VM from template
New-VM -Name $VMName -Template $Template -VMHost $ESXi -Datastore $Datastore -Location $Location -OSCustomizationSpec $Custom
    
#Change VM's vCPU, Memory, NetworkAdapter
$NewVM = Get-VM -Name $VMName
$NewVM | Set-VM -MemoryGB $Memory -NumCpu $vCPU -Confirm:$false
$NewVM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $Network -Confirm:$false
}