How To Identify the Physical Host of a Virtual Server
One of the drawbacks of using Virtual Server is that it's very difficult to avoid sprawl. Even in a well-managed enviroment, if you have a large number of VMs, it's possible that at some point you'll lose track of what physical server is home to a particular virtual server. Moreover, you may also find "unauthorized" virtual machines popping up all over the place.
Network admins who manage a large number of servers from a single KVM are familiar with a similar problem. When you have a dozen servers managed from a single console, how do you quickly tell what server you're looking at? Most of us use a utility called BGInfo to solve this problem. BGInfo, one of the free Sysinternals tools available from Microsoft, creates a desktop wallpaper which shows a number of server settings: hostname, IP address, hard disk volumes info, operating system version, service pack level, and so on.
There is a similar solution for virtual servers... and in fact, if you like BGInfo, you can make BGInfo part of that solution.
It turns out that a Microsoft Virtual Server actually stores the name of the physical host in the virtual machine's registry. This means that we can determine the physical host from a command session within the virtual machine. It also means that we can display that information using BGInfo.
The physical host is stored in the registry at this location:
You can display (or even edit) registry values from the command line using reg.exe. With that in mind, I typically create a dirt-simple batch file named "showhost.bat," and I copy it to all my virtual servers. The batch file contains the following:
Now, if I want to know where a server is hosted, I can just execute showhost.bat, and presto... I have my answer. But why not make it even easier? Let's use BGInfo to do just that.
One of the many terrific things about BGInfo is that you're not limited to displaying the default fields. You can define custom fields to display additional information. You can display environment variables, file contents, file versions, timestamps, VBScript or WMI queries... or registry keys.
To display the physical host, all we have to do is add a custom field which shows the previously noted registry key.
Kinda cool, huh? It beats the hell out of the old kludge of ejecting the CD to find the server!
At this point, I don't have an installation of Hyper-V, so I can't tell you whether or not the same method works there. And, regrettably, this method does not work with VMWare virtual machines.