What physical computer am I on?

What physical computer am I on?

Rate This
  • Comments 8

Once you start to get more and more virtual machines, and more and more Hyper-V servers, in your environment it can get quite hard to keep track of where a specific virtual machine is actually running.

System Center Virtual Machine Manager can help you out here – but what if you are not sitting at the  System Center Virtual Machine Manager Console?  What if you have used Remote Desktop to connect to the virtual machine?  What do you do then?

A long, long time ago – I posted information on how to figure out the host operating system from inside a virtual machine using a VBScript on Virtual PC and Virtual Server.  And this script also works on Hyper-V!

But no one uses VBScript anymore! Right?  So how do we do this in PowerShell?

The answer is with a one-liner of course! (or actually – three one liners).

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

And of course – this will work on Hyper-V, Virtual Server and Virtual PC.


Leave a Comment
  • Please add 5 and 8 and type the answer here:
  • Post
  • What we need is a way for BGInfo to launch a PowerShell cmdlet so the info could be placed onto the backdrop

  • Maybe PSHyperv should have some simple cmdlets to install inside the VM to have something nicer like get-parent etc.

  • Do you think storing physical machine fqdn on vm registry is a secure thing? You're leaving an open door for customers who use vm as a service, i think. Also what happens to that registery key if vm runs on hyperv cluster?

  • Ok, I tested it. I migrate one of the virtual machine to another host with live migrate feature. After host changing, registry keys rapidly replaced by the new host's information. Then I stopped the Hyper-V Data Exchange service. Live migrated the virtual machine another host. Registry remained same. After starting the service again, registry changed again.

    Is there a way to control Hyper-V Data Exchange service? Is that possible to execute scripts on virtual machine via Hyper-V Data Exchange service?

  • What's the difference between 'HostName' and 'PhysicalHostName' ?


  • isn't it a security problem? I mean it could be a potential hint for an attack vector.

  • Dave Dustin -

    I agreee!

    Yusuf Ozturk / kirill kovalenko-

    We do not see this as a security risk.  We have always designed our system with the assumption that the bad guy in a VM would be able to figure out that they were in a VM - and then ensure that there is nothing that they could do with that information.  In this case - the only real risk is that a bad guy could try to launch a network based attack against the host (in which case - being in a VM gives them no advantage when compared to being a seperate physical computer)

    If this is a concern to you - there are two options you could take:

    1) Configure the virtual machines so that they cannot attempt to connect to the host over the network.  To do this configure an "external only" network that connects to a different physical network than the one the host is connected to.

    2) Disable the data-exchange integration services under the virtual machine settings (which will stop this information from being sent in the first place).

    Ran -

    If you are in a cluster, HostName will return the cluster name and PhysicalHostName will return the node name.  Otherwise they are the same.



  • I have different virtual machines (ex: servers.txt) available and i need to get host name of all by passing the VM name.. using foreach or any other way ?

Page 1 of 1 (8 items)