How to check my windows server is virtual machine or physical machine

ljh picture ljh · Mar 18, 2013 · Viewed 37.9k times · Source

I'm remoting desktop to windows servers in our Lab/datacenter. I have a requirement to figure out all our servers are virtual machines or physical servers programatically, certainly we have the environment sheet tell us which is which. But I need to write code to distinguish it. What technique I need to use? I didn't find a .Net Assembly to do that. Looking for expert to share your knowledge or guidance, any research direction or link, anything will be appreciated!

Answer

user2151805 picture user2151805 · Mar 18, 2013

You can try to use the following PowerShell script, it utilizes WMI to find out if machine is virtual machine or physical machine.


gwmi -q "select * from win32_computersystem"
Certainly, you can use C# code to query WMI too. The output of script above will be like following:

Domain:   ...
Manufacturer: Microsoft Corporation
Model: Virtual Machine
Name : .....
....