Add-PSSnapin *vmware*
$passwd = Read-Host "input your vcenter password: " -AsSecureString
Connect-VIServer -Server 10.10.10.10 -User administrator@vsphere.local -Password $passwd
$vms = Import-CSV E:\NewVMs.csv
foreach ($vm in $vms){
$Template = Get-Template $vm.template
$VMHost = Get-VMHost $vm.Host
$Datastore = Get-Datastore $vm.datastore
$OSCustomization = Get-OSCustomizationSpec $vm.customization
$ResourcePool = Get-ResourcePool $vm.ResourcePool
New-VM -Name $vm.name -OSCustomizationSpec $OSCustomization -Template $Template -VMHost $VMHost -ResourcePool $ResourcePool -Datastore $Datastore -RunAsync
}
来源:oschina
链接:https://my.oschina.net/u/4280951/blog/4341985