page contents

About the Post

Author Information

HOW TO: Find the Physical host of a VM in Hyper-V

With the rising popularity of virtual machines, you may find yourself one day logging into a server troubleshooting an issue. Then all of a sudden it occurs to you that you are not sure if this machine is Physical or Virtual. Better yet you know this is a VM, but you are not sure which cluster node is the owner.

You could look for it in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

But that gets old after a while, especially if you are doing it across many servers. Well, there is a much easier way

This will require you to run either a script or issue instructions from a command line!

For all of these steps you will need to log into the VM.

Easiest Method:

I found a really cool batch file from TechNet that pulls this information from the registry. But it only works for these OS versions:

Windows Server 2012  No
Windows Server 2008 R2 Yes
Windows Server 2008   Yes
Windows Server 2003  No
Windows 8  No
Windows 7  Yes
Windows Vista  No
Windows XP Yes
Windows 2000 No

Preferred Method:

To get the name of the physical computer that you are running on, open a PowerShell inside the virtual machine and type in:

(Get-ItemProperty-path “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).PhysicalHostName

You can also get the fully qualified name of the physical computer by running:

(Get-ItemProperty -path “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).PhysicalHostNameFullyQualified

Finally, you can get the name of the virtual machine itself by running:

(Get-ItemProperty-path “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).VirtualMachineName

Bonus Points
All these commands will work on Hyper-V, Virtual Server and Virtual PC.

PowerShell and WMI:

I also found this on TechNet as well with this article.

Using WMI and PowerShell

function Get-VMOSDetail
        $ComputerName = $Env:ComputerName,
    # Creating HASH Table for object creation
    $MyObj = @{}
    # Getting VM Object
    $Vm = Get-WmiObject -Namespace root\virtualization -Query "Select * From Msvm_ComputerSystem Where ElementName='$VMName'" -ComputerName $ComputerName
    # Getting VM Details
    $Kvp = Get-WmiObject -Namespace root\virtualization -Query "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent" -ComputerName $ComputerName
    # Converting XML to Object
    foreach($CimXml in $Kvp.GuestIntrinsicExchangeItems)
        $XML = [XML]$CimXml
            foreach ($CimProperty in $XML.SelectNodes("/INSTANCE/PROPERTY"))
                switch -exact ($CimProperty.Name)
                    "Data"      { $Value = $CimProperty.VALUE }
                    "Name"      { $Name  = $CimProperty.VALUE }
    # Outputting Object
    New-Object -TypeName PSCustomObject -Property $MyObj


Tags: , , , , , , , ,

2 Responses to “HOW TO: Find the Physical host of a VM in Hyper-V”

  1. Aw, this was an incredibly good post. Taking a few minutes and actual
    effort to generate a very good article… but what can I
    say… I put things off a whole lot and don’t seem to get nearly anything done.

    February 23, 2014 at 4:06 PM


  1. HOW TO: Find the Physical host of a VM in Hyper –V - SQL Server - SQL Server - Toad World - July 8, 2013

    […] the complete post at…/how-to-find-the-physical-host-of-a-vm-in-hyper-v 0 […]

Copy Protected by Chetan's WP-Copyprotect.