编辑一个VBScript脚本文件:
On Error Resume Next
Set virtualServer = CreateObject("VirtualServer.Application")
set vmCollection = virtualServer.VirtualMachines
For Each vm in vmCollection
Wscript.Echo "=============================="
Wscript.Echo "Name: " & vm.Name
Wscript.Echo "Notes: " & vm.Notes
Wscript.Echo
Wscript.Echo "Configuration File: " & vm.File
Wscript.Echo
Wscript.Echo "Memory: " & vm.Memory & "M"
Wscript.Echo
WScript.Echo "State: " & VM.State
If vm.State=1 or vm.State=2 Then 'Off and saved
Wscript.Echo "Auto Startup "
vm.Startup
WScript.Sleep WScript.Arguments(0) & "000"
WScript.Echo "New State: " & VM.State
End If
Wscript.Echo "=============================="
Next
Set virtualServer = CreateObject("VirtualServer.Application")
set vmCollection = virtualServer.VirtualMachines
For Each vm in vmCollection
Wscript.Echo "=============================="
Wscript.Echo "Name: " & vm.Name
Wscript.Echo "Notes: " & vm.Notes
Wscript.Echo
Wscript.Echo "Configuration File: " & vm.File
Wscript.Echo
Wscript.Echo "Memory: " & vm.Memory & "M"
Wscript.Echo
WScript.Echo "State: " & VM.State
If vm.State=1 or vm.State=2 Then 'Off and saved
Wscript.Echo "Auto Startup "
vm.Startup
WScript.Sleep WScript.Arguments(0) & "000"
WScript.Echo "New State: " & VM.State
End If
Wscript.Echo "=============================="
Next
在Virtual Server的Server Properties中Enable scripts attached to this server
并在Command-line action when Virtual Server starts:中填入:
cscript AutoStart.vbs 15
这个15是每个虚机启动的延时秒数,因为如果不延时,就会发生N个虚机一窝蜂同时启动,给主机的带来巨大的负担。
另外,在每个虚机的General properties配置里,应该选中Run virtual machine under the following user account:,并指定一个可以在本地登录的用户账户名及口令,这个账户建议使用最小权限的账户,一般能够读写和执行虚机定义及虚拟盘文件即可(详细权限要求请查阅Virtual Server Administrator's Guide),不指定这个账户将无法运行脚本。
虽然,就在这个地方我们可以设置自动启动及启动的延时,但每次增减虚机时时还要查看现有的设置情况,以决定错开启动的延迟时间,比较麻烦,有了这个脚本你可以一劳永逸,稍作修改还可以实现更复杂的逻辑。