Hyper-V Program Manager
Here are some simple scripts that allow you to start a virtual machine with Windows Virtual PC. Now, you may be wondering why you would want to do this. Well there are a couple of reasons I can think of:
# Check for correct command-line arguments
If ($vmName -eq "")
write-host "Missing command-line argument."
write-host "USage: StartVM.ps1 -vmName `"Name of virtual machine`""
# Connect to Virtual PC
$vpc=new-object –com VirtualPC.Application –Strict
# Get virtual machine object
$vm = $vpc.FindVirtualMachine($vmName)
# Start the virtual machine
write-host "Starting the virtual machine " $vmName "..."
$vmTask = $vm.Startup()
# Wait for the virtual machine to start
# Display success or failure
If ($vmTask.result -eq 0)
write-host "Virtual machine started."
write-host "Failed to start virtual machine."
Dim namedArguments, vpc, vm, vmName, vmTask
' Check that the script is running at the command line.
If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
WScript.Echo "This script must be run under CScript."
' Get the virtual machine name from the command-line arguments
Set namedArguments = WScript.Arguments.Named
If namedArguments.Exists("vm") Then
vmName = namedArguments.Item("vm")
WScript.Echo "Missing command-line argument"
WScript.Echo "Usage: StartVM.vbs /vm:" & chr(34) & "Name of virtual machine to be started" & chr(34)
' Attempt to connect to Virtual PC
On Error Resume Next
Set vpc = CreateObject("VirtualPC.Application")
If Err.Number <> 0 Then
WScript.Echo "Unable to connect to Virtual PC."
On Error Goto 0
' Get virtual machine object
Set vm = vpc.FindVirtualMachine(vmName)
' Start the virtual machine
WScript.Echo "Starting the virtual machine " & vmName & "..."
Set vmTask = vm.Startup
' Wait for the virtual machine to start
' Display success or failure
If vmTask.result = 0 Then
WScript.Echo "Virtual machine started."
WScript.Echo "Failed to start virtual machine."
I have also attached these scripts to this post.
Is it possible to also configure a log off script to shut down a running VM?
I use Windows on my media center and then have my email server running in a VM on the same box. Virtual Server lets you start/stop the VM with the service, is there a way I could mirror this functionality in Win7 using Virtual PC?
Yes, you can script shutting down a virtual machine, but getting it to run on logoff would be tricky.
Is there any possibility to turnoff a hibernated windows virtual pc machine? When trying your code and executing the turnoff method instead of the startup methods it results in an error stating that the maschine is not running.
What is the commant to shut down a VM? Is it possible to shutdown all the VMs at the same time? Which command?