views:

383

answers:

3

Are there any means for a .NET application to create, delete, start, and stop Hyper-V virtual machines?

I would like to create an automated means of starting and stopping (the create & delete are bonus) virtual machines from a C# application. I figured that (atleast) there would be a means of doing this via P/Invoke, but I cannot find anything discussing how to do this.

Any links to some good walkthroughs or documentation would be preferable.

+1  A: 

System Center Virtual Machine Manager comes with a very good set of .NET assemblies, which you can freely reference in your app. It also has an excellent Powershell interface for easy scripting.

However, if you're working with raw Hyper-V and not SCVMM, then I don't know. See if you can get your boss to spring for SCVMM.

JSBangs
+1 for PowerShell. It appears that Microsoft is planning to leverage that for administering multiple enterprise applications.
TrueWill
+3  A: 

Much of the Hyper-V automation is through WMI. WMI isn't explicitly a .NET API, but it's pretty easy to work with from .NET.

The Hyper-V WMI API docs are at http://msdn.microsoft.com/en-us/library/cc136992%28VS.85%29.aspx

anelson
Thanks! That was just what I was looking for.
Jason Whitehorn
+1  A: 

WMI wrapper in C# for Hyper-V available at http://hypervlib.codeplex.com

Anton