Select Page

VBScript for Start/Stop/Save Hyper-V VMs…

I found this useful bit of VBScript code from Ben Armstrong:
http://blogs.msdn.com/virtual_pc_guy/archive/2008/01/29/starting-a-hyper-v-virtual-machine.aspx

Here it is basically:
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:\.rootvirtualization”)

‘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)

Pin It on Pinterest