PowerCLIscript#PowerCLItocreatemulti"/>

PowerCLI to create multiple VMs from template

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PowerCLI to create multiple VMs from template相关的知识,希望对你有一定的参考价值。

CSV format


技术分享


PowerCLI script


#PowerCLI to create multiple VMs from template

Add-PSSnapin vmWARE.VimAutomation.Core
$vc="devvc55"
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
}

以上是关于PowerCLI to create multiple VMs from template的主要内容,如果未能解决你的问题,请参考以下文章

Powercli随笔 - PowerCLI script to sequentially Storage vMotion VMs from a CSV File

Add PortGroup to all hosts in cluster with PowerCLI

Powercli Get-OvfConfiguration部署ova虚拟机

powercli 批量配置vmhost 初始信息

[简版]VMware强大的管理工具-PowerCLI

PowerCLi 管理VMware vCenter 批量部署导出导入