How to check my windows server is virtual machine or physical machine
Asked Answered
S

9

18

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!

Sixtieth answered 18/3, 2013 at 19:49 Comment(0)
E
20

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 : .....
....
Evincive answered 18/3, 2013 at 20:18 Comment(0)
C
9

To check this from the command prompt you can run this: systeminfo | Select-String "System"

Example output for virtual server:

System Manufacturer:       Microsoft Corporation    
System Model:              Virtual Machine    
System Type:               x64-based PC

Example output for physical server:

System Manufacturer:       HP
System Model:              ProLiant BL460c G6
System Type:               x64-based PC
Contemporize answered 8/8, 2013 at 10:49 Comment(2)
I received "FIND: Parameter format not correct" Should be some modification for your command line example? I am using PowerShell version 5.1.Overstride
Thanks @CloudCho, I've upadated the command to use Select-String instead of find.Contemporize
R
6

As far as I know there is no easy way to do this.

There are a few workarounds but there is, at least as far as I know, not a one-size-fits-all solution.

Ben Armstrong wrote a post about Detecting Microsoft virtual machines and there's a low-level trick which can determine whether you are running within a Virtual PC or VMWare but that still leaves out VirtualBox and others.

A trick you might want to try is to detect whether VMWare Tools or VirtualBox Tools are installed. In most cases they are installed on the guest OS to provide needed features but it will be hard to maintain the different installation GUIDS on your end so it's not an ideal solution.

--- Also , if the VM is running in a Linux KVM environment, the output is like this one enter image description here

Rockett answered 18/3, 2013 at 20:2 Comment(0)
R
3

There is no easy way to tell if you're running in a bare metal or in a virtual computer, the best thing you can do is to get some hardware info and made an educated guess, for example, if the machine have a network adapter which contains Microsoft, VMware, Oracle, Hyper-V, Virtual or VirtualBox, most likely it's a virtual machine given that neither Microsoft, Oracle, or VMware fabricate network cards.

As you use C#, the class for retrieving this and other hardware info is ManagementClass, also there is this nice project that let you retrieve tons of info from your computer using ManagementClass.

Roxanaroxane answered 18/3, 2013 at 20:9 Comment(0)
D
1

Run the systeminfo command in the command prompt to see the system manufacturer and system model details. There you can find the virtual and physical machine information.

Danaedanaher answered 2/4, 2013 at 18:8 Comment(0)
S
1

Try this:

FOR /F "tokens=*" %a IN ('wmic bios get bioscharacteristics^|find /c "33"') DO set USBlegacy=%a

This returns "1" for the limited range of desktops and laptops in my environment and "0" for VMWare workstation 9, ESX 5.5, and Citrix 6.5 and 7.6. BIOSCharacteristic "50" (one "reserved for system vendor") I've only found in the four virtual environments so that would work in reverse.

Edit: or there's this:

FOR /F "tokens=*" %a IN ('wmic path win32_pnpentity get ^|find /c "ACPI Fan"') DO set ACPIfan=%a

Returns "5" on an HP Desktop, "0" on VMware workstation 9 and ESX 5.5, not tested on the others.

Skidway answered 14/7, 2015 at 13:37 Comment(3)
Returns 0 on physical windows 10 on notebookEntozoic
Is that a '0' for "ACPI Fan"? Makes sense if the notebook has no fan. My Dell Precision m3800 laptop in Windows 10 returns '2' for "ACPI Fan" (and '1' for "USBlegacy")Skidway
Yep. ACPI Fan = 0Entozoic
P
0

you can use this command in cmd or powershell

SYSTEMINFO

You will find a line with the following text (or similar):

System Manufacturer: VMware, Inc. System Model: VMware Virtual Platform

Possing answered 23/12, 2017 at 6:44 Comment(0)
J
0

This works very well in Powershell:

$ecv = (get-wmiobject win32_BIOS).EmbeddedControllerMajorVersion
$isPhysical = $ecv -gt 0 -and $ecv -lt 255

A VM does not have a controller or has a dummy-value of '0' as a version.

Jodoin answered 16/3, 2023 at 7:38 Comment(2)
windows in vmware has vaule of 255Dahlgren
Thank you for the input. I updated the scriptlet to cover that VMware dummy value, too.Jodoin
A
-3

The only *programmatic* way I know of doing this reliably is:

  1. Write an app that crawls your network (or IP range) to get a list of machines.
  2. Display those machines to a person and ask them to check a box if it's a VM...
  3. Print the report.
Adaliah answered 18/3, 2013 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.