[Script] Listing Virtual Machines with Windows Virtual PC

[Script] Listing Virtual Machines with Windows Virtual PC

  • Comments 4

To get things started here, I thought I would put up some samples for the most basic scripts I could think of for interacting with Windows Virtual PC.  So here is a sample script that just lists the virtual machines that are currently registered on the local system:

PowerShell:

# Connect to Virtual PC
$vpc=new-object –com VirtualPC.Application –Strict
 
write-host "Virtual Machines:"
write-host "================="
 
# Iterate over the virtual machines and display their names
foreach ($vm in $vpc.VirtualMachines)
    {
    write-host $vm.name
    } 

 

VBScript:

option explicit
 
Dim vpc
Dim vms
Dim vm
 
'Connect to Virtual PC
Set vpc = CreateObject("VirtualPC.Application")
 
'Get collection of virtual machines
set vms = vpc.VirtualMachines
 
Wscript.Echo "Virtual Machines:"
Wscript.Echo "================="
 
'Iterate over the virtual machines and display their names
For Each vm in vms
    Wscript.Echo vm.Name
Next

 

Cheers,
Ben
Leave a Comment
  • Please add 6 and 1 and type the answer here:
  • Post
  • I am running Win7 RC. I have VPC 6.0 installed. I get an error doing the New-Object

    PS C:\> $vpc=new-object -com VirtualPC.Application -Strict

    New-Object : Cannot load COM type VirtualPC.Application.

    At line:1 char:16

    + $vpc=new-object <<<<  -com VirtualPC.Application -Strict

       + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException

       + FullyQualifiedErrorId : CannotLoadComObjectType,Microsoft.PowerShell.Commands.NewObjectCommand

  • Doug -

    Are you using Virtual PC 2007, or Windows Virtual PC?

    Cheers,

    Ben

  • Is there something similar to enumerate the machines for VirtualPC 2007?

  • Nikhil -

    No, Virtual PC 2007 has no scriptable interface.

    Cheers,

    Ben

Page 1 of 1 (4 items)