虚拟机克隆与配置脚本
编写并验证通过的脚本如下,执行后可完成虚拟机克隆及配置,参考如下。
##执行前提1:需要在vcenter client创建自定义规范$basespec,vcenter server sysprep相关目录中存在win2003的sysprep文件.
##执行前提2:所操作的虚拟机、或模板需安装vmtools
##将脚本编写至**.ps1文件中,如clonenewvm.ps1,打开PowerCli命令行,执行./clonenewvm.ps1即可
##连接VC
Connect-VIServer -Server 192.168.5.203 -Protocol https -User administrator@vsphere.local -Password AAaa11!!
##相关参数(以下为例,实际使用可通过其他方式或脚本配置),依次为宿主机、克隆后配置的虚拟机名称、模板、克隆后虚拟机存放的硬盘、自定义规范
#创建虚拟机语法
New-vm -vmhost $vmhost -Name $name -Template $template -Datastore
$datastore -OSCustomizationspec yijia
New-vm -vmhost 192.168.5.201 -Name win7-1 -Template win7 -Datastore datastore2 -OSCustomizationspec yijia
##启动虚拟机
#start-vm $name
##断开连接
Disconnect-VIServer $vc -confirm:$false