18

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Jason Whitehorn
  • 13,585
  • 9
  • 54
  • 68
  • There's a nicely populated WMI namespace at `root\hypervisor` -- I'm not sure where it's documented, but you can browse through the classes/instances/methods there yourself. – ephemient Nov 14 '09 at 23:43

4 Answers4

16

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.

See Hyper-V WMI API docs and older v1 docs.

Alexander Malakhov
  • 3,383
  • 2
  • 33
  • 58
anelson
  • 2,569
  • 1
  • 19
  • 30
4

Don't forget to take into consideration that in newest releases of hyper-v, the namespaces have been moved to v2. For example from root\virtualization in Hyper-V 2008, the namespace has changed into root\virtualization\v2 in 2012. (Windows Server version) Check this post for more details.

This helped me a lot in newest versions of Hyper-V

Hope it helps.

wazza
  • 101
  • 3
2

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.

JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
  • +1 for PowerShell. It appears that Microsoft is planning to leverage that for administering multiple enterprise applications. – TrueWill Nov 15 '09 at 04:09
1

You can do that and much more with this. http://archive.msdn.microsoft.com/ddc It is for hosters but can be easily installed on premise.

Ahmed
  • 11
  • 1