CSV format
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
}
附件:http://down.51cto.com/data/2366887
本文转自学海无涯博客51CTO博客,原文链接http://blog.51cto.com/549687/1950884如需转载请自行联系原作者
520feng2007