僅對 R2 有作用

http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/01/29/starting-a-hyper-v-virtual-machine.aspx

VBScript:

Option Explicit
 
Dim WMIService
Dim VMList
Dim VMName
 
'Specify the name of the virtual machine that I want to start
VMName = "Windows Server 2003"
 
'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
 
'Query for the specific virtual machine that I want to start
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & VMName & "'")
 
' Request a state change on the first VM that is returned
' 2 = start, 3 = stop and 32769 = save state
VMList.ItemIndex(0).RequestStateChange(2)
 

PowerShell:

#The name of the virtual machine to be started
$VMName = "Windows Server 2003"
 
#Get the VM Object
$query = "SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" + $VMName + "'"
$VM = get-wmiobject -query $query -namespace "root\virtualization" -computername "."
 
#Request a state change on the VM
$Result = $VM.RequestStateChange(2)

 

全站熱搜
創作者介紹
創作者 it168 的頭像
it168

it168 資訊分享空間

it168 發表在 痞客邦 留言(0) 人氣()