Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the hyper v role of windows server 2008 R2. I want to install OS in the virtual machine through C# code.

Also if there is an existing VHD of other VM can I able to link that VHD to a new VM with C# code. Waiting for your help.

share|improve this question

Ah. No. You can not never ever install an OS from C# code, you know. How would you do that on a physical server?

There are some ways to autoamte the setup process. They are windows integrated (unattended install) and a prepared image could possibly use a .NET program to pull an answer file automatically, but that is something different than you asked for.

can I able to link that VHD to a new VM with C# code

All the configuration you can easily do from any windows integrated language (which includes any .net language). Hyper-v, being a windows system feature, is fully exposed through WMI.

has some starts for using PowerShell, the same principles apply for any WMI capable language.

share|improve this answer

C# is just a language, and much like any other. The question you're asking has little to do with language.

If you're asking if you can programmatically manipulate a VM under Hyper-V, the answer is yes. Hyper-V is entirely managed through WMI interfaces, as defined here:

You can interact with that in C#, using the .Net WMI classes, or you can (probably more easily) drive PowerShell cmdlets with your C# code. Whichever you're more comfortable with, they'll be more similar than different, as they both resolve down to .Net classes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.