29 June 2012

Script to determine if a server is physical or virtual

Have you ever remotely logged on to a server or PC and wondered if it is physical or virtual?   And if it is virtual is it Hyper-V or VMware.  Sometimes it is easy to tell because of virtual machine extension being installed and leaving a nice little icon in the system try.  But what if it is not obvious?

This little VBscript will return the value of the Manufacturer and the model.

So if it is physical it will give you

VMware machines will give you

Hyperv-V will give you

Here is the script:

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystemProduct",,48)
For Each objItem in colItems
Val1 = "Vendor: " & objItem.Vendor
Val2 = "  Model: " & objItem.Name
Wscript.echo val1 & Val2Next

No comments:

Post a Comment