使用VMware PowerCLI从模版批量新建虚拟机
- 发布时间:2020-07-20
- 来源:
- 浏览次数:4124
专业科普小课堂:
有一个需求,新建200个虚拟机,这要是一个一个去建那我可就疯了。想起之前听vmware原厂工程师说过的这个powercli,就着手研究了一下。南昌互联网APP小程序
将以下文件存储为 *.ps1
#在使用时应使用VMware PowerCLI (32-Bit)
$vc='86.12.92.4' #vc地址
Connect-VIServer -Server $vc -username "administrator@vsphere.local" -Password "123" #vc用户名&密码
$vmhost="86.12.87.66" #指定主机
$namestart="test" #虚拟机test名称
$template="CentOS_7.7_X64_scanned" #使用模板
$datastore="vsanDatastore_Desktop" #使用存储
$custsysprep = Get-OSCustomizationSpec linux #自定义规范,需要现在vc中配置,vsphere6.5 策略和配置文件>自定义规范管理器>创建新规范
$network="86.12.101.*" #指定使用的端口组,写端口组名称
#$ipstart="86.12.101." #可以指定ip的开始地址,不过我不太会用
$endipscope=1..1 #可以指定虚拟机的数量,例如:1..2就是建两台虚拟机
foreach($endip in $endipscope)
{
#$ip=$ipstart+$endip
$name=$namestart+$endip #虚拟机名
#$custsysprep|Set-OScustomizationSpec -NamingScheme fixed -NamingPrefix $name
#$custsysprep|Get-OSCustomizationNicMapping|Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask 255.255.255.0 -Dns 86.12.24.2 -DefaultGateway 86.12.101.254 New-VM -Name $name -VMHost $vmhost -Portgroup $network -Datastore $datastore -Template $template -OSCustomizationSpec $custsysprep
}
#之前在网络选择是使用的是-NetworkName选项,这个选项已经不再被支持。会触发警告: Specifying a distributed port group name as network name is no longer supported. Use the -Portgroup parameter.
- 返回上一级
- 下一篇:excel VBA是什么?
- 上一篇:微信又又又又更新了。这些你GET到了吗
联系我们
只要关乎创意 建站 视觉 开发,嘉瑞都能帮您实现
-
业务咨询
18970825117 18970985102
8年专注网站建设
-
QQ咨询
350941543
倾力打造优质产品
-
微信咨询
18970985102
一对一为您量身设计
-
服务热线
18970825117
100+用户诚意推荐