将以下文件存储为 *.ps1
然后在PowerCLI中运行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#在使用时应使用VMware PowerCLI (32-Bit) $vc='86.12.9.9' #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 96.12.24.2 -DefaultGateway 96.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. |
想了解更多的参数信息、使用方方法可以参考文末的资料。如果有大佬也希望给予帮助改进。
参考了以下资料:
[1]VMware PowerCLI5.1在线手册 https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FSet-OSCustomizationSpec.html
[2]安装PowerCLI https://docs.vmware.com/cn/VMware-vSphere/6.5/com.vmware.vsphere.install.doc/GUID-F02D0C2D-B226-4908-9E5C-2E783D41FE2D.html
[3]PowerCLI各版本下载 https://code.vmware.com/web/tool/12.0.0/vmware-powercli
© 著作权归作者所有
文章评论(0)