tags:

views:

140

answers:

1

I've got a Hyper-V host, with several guests, each with one or more network adapters. How do I enumerate the network adapters on those guests?

Specifically, I'm looking for a particular guest, given a MAC address.

I'm using C# and System.Management.

A: 

I'll leave out some of the details:

  • Connect to Hyper-V on the host.
  • Enumerate the machines (SELECT * FROM Msvm_ComputerSystem).
  • For each machine, find the associated Msvm_SyntheticEthernetPort objects.
var ports = computerSystem.GetRelated("Msvm_SyntheticEthernetPort");
foreach (ManagementObject port in ports)
{
  • Get hold of the settings:
    var portSettings = port.GetRelated("Msvm_SyntheticEthernetPortSettingData");
    foreach (ManagmentObject portSetting in portSettings)
    {
  • Look for the configured MAC address:
        string macAddress = (string)portSetting .GetPropertyValue("Address");
Roger Lipscombe