In this simple post, I’ll show you how to find the Hyper-V hostname of a virtual machine. This would be useful for finding out which host a particular VM is running on.

There are a number of ways to do this. For example, adding the host to Hyper-V Manager would probably be the easiest method.

But what if you have a ton of hosts to search through? Or what if one of your users has Hyper-V installed on their desktop computer and this VM shows up in your asset management/inventory reports?

So, in this guide, I’ll show you two different options: either by finding the physical host name in the registry by Remote Desktop’ing into the server, or by using a simple Powershell script. Just run the script from your machine, enter a VM name, and it’ll tell you which host it’s located on.

Another handy script I wrote will export a list of Hyper-VM VM Names from all of your hosts. I typically run this monthly for data recovery purposes. If a server crashes, it’s always good to know exactly which VM’s were running on it.

Method 1: Find Host of a VM from the Registry

This is the easier method, although it’s a bit more cumbersome. Simply open Remote Desktop and RDP to the VM in question.

Then, open Regedit.

Expand HKEY_LOCAL_MACHINE/Software/Microsoft/Virtual Machine/Guest/Parameters.

Under the Hostname, PhysicalHostName, or PhysicalHostNameFullyQualified keys, you’ll see the host server that VM is sitting on.

Method 2: Use Powershell to find Host of Hyper-V VM

Note: You will need the Remote Registry Service running on the virtual machines for it to return info.

Open Powershell. Then paste in the command below. It will prompt you to enter the VM name, and then it’ll display which host it’s running on.

$vm = read-host "Please enter the VM Name"
$hostinfo = ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$vm)).OpenSubKey('SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').GetValue('PhysicalHostName')
write-output " Guest VM '$vm' is hosted on '$hostinfo'"

Although it shows an error, it still correctly shows me the host it’s running on.

During my testing, not all VM’s throw that error message, so I’m assuming it’s either operating system specific or the remote registry isn’t running.

If it doesn’t return anything, you can use the code below to confirm whether or not the RemoteRegistry service is running. Note: By default, Windows keep this disabled.

Powershell Script to Check if RemoteRegistry Service is Running on Remote Computer

$vm = Read-host "Enter VM Name"
Get-Service -Name RemoteRegistry -ComputerName $vm

Enable Remote Registry Service using Powershell

Get-Service -ComputerName $vm -Name RemoteRegistry | Set-Service -StartupType Manual -PassThru| Start-Service

Disable Remote Registry Service using Powershell

Get-Service -ComputerName $vm -Name RemoteRegistry | Set-Service -StartupType Disabled -PassThru| Stop-Service

Wrapping Up

Hopefully this simple guide helped you locate the host one of your virtual machines!

My Homelab Equipment

Here is some of the gear I use in my Homelab. I highly recommend each of them.

The full list of server components I use can be found on my Equipment List page.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *