In the past I have lamented about how hard it is to use PowerShell to control Virtual Server. Luckily it is much easier with Windows Virtual PC. There is no need to load interop code – instead you can just point PowerShell at Virtual PC and go:
All you need to get started is to connect to the Virtual PC COM object by using this command:
$vpc=new-object –com VirtualPC.Application
You can then examine properties and call methods on this COM object directly. Very cool.
For those of you who want to know the gory details of why this is easy with Virtual PC and hard with Virtual Server: Virtual Server runs as network process by default, and then uses impersonation to run virtual machines under the current users context. Using COM + PowerShell + impersonation is very problematic. Virtual PC, on the other hand, just runs directly under your use context – and hence there is no need to do any impersonation and everything “just works”. Also, the reason why Virtual Server needs to use this more complicated model is to support running virtual machines when no user is logged in to the physical computer. Virtual PC does require a user to be logged into the physical computer in order to run a virtual machine.