Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

What Are You?

Posted on October 23, 2015October 23, 2015

Here's a quick way to tell whether a given machine is real or not: check the Win32_Baseboard class. You can use either Get-WmiObject or Get-CimInstance. Notice the results from a few physical machines.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Now see the result when querying a Hyper-V virtual machine:

I don't have any VMware available so I don't know what kind of result that would show. I also haven't done extensive testing with items like a Microsoft Surface. I threw together this simple function you could use.

#requires -version 4.0

Function Test-IsVM {
[cmdletbinding()]
Param(
[Parameter(
 ValueFromPipeline,
 ValueFromPipelineByPropertyName,
 HelpMessage = "Enter the name of a computer")]
[ValidateNotNullorEmpty()]
[string]$Computername = $env:COMPUTERNAME
)

Begin {
    Write-Verbose "Starting: $($MyInvocation.Mycommand)"  
    $paramHash = @{
        ClassName = 'Win32_Baseboard'
        ErrorAction = 'Stop'
}
} #begin

Process {
    Write-Verbose "Querying $computername"
    Try {
        $paramHash.ComputerName = $Computername
        $data = Get-CimInstance @paramHash
        if ($data.Product -match "virtual") {
            $True
        }
        else {
            $False
        }
    }
    Catch {
      Write-Warning "$($computername.ToUpper()) : $($_.Exception.message)"
    }
} #process

End {
    Write-Verbose "Ending: $($MyInvocation.Mycommand)"
} #end

} #end function

Have fun.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

8 thoughts on “What Are You?”

  1. Mike Shepard says:
    October 23, 2015 at 10:04 am

    Just tried it on a VMWare box and got this:

    Product : 440BX Desktop Reference Platform

    1. Jeffery Hicks says:
      October 23, 2015 at 10:41 am

      Thanks for the info. Is this from something running under VMware Workstation or a Vsphere server? In either case, it wouldn’t be hard to adjust the function to account for that product.

      1. Igor says:
        October 23, 2015 at 11:20 am

        My VMs (under vSphere) are returning also 440BX Desktop Reference Platform

      2. Jeffery Hicks says:
        October 23, 2015 at 12:55 pm

        Thanks for testing. That is easy enough to test for with a regular expression.

  2. Benjamin Armstrong says:
    October 23, 2015 at 8:15 pm

    You can see how to detect other people here: http://social.technet.microsoft.com/wiki/contents/articles/942.hyper-v-how-to-detect-if-a-computer-is-a-vm-using-script.aspx

  3. Jay Adams says:
    October 26, 2015 at 9:10 am

    Checking the Model in the Win32_ComputerSystem class has always worked well for me. Good news is: Both are populated even back to Windows Server 2003 for those who still have to code for it.

    1. Jeffery Hicks says:
      October 26, 2015 at 9:28 am

      Yep, that works as well.

  4. Powershell Administrator says:
    November 20, 2015 at 5:55 am

    You can also get this information from the registry (in case of Hyper-V, don’t know about VM ware or other environments).
    $IsVM = Test-Path “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”
    If($IsVM)
    {
    $VMHost = (Get-Item “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).GetValue(“HostName”)
    }

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d