How do I enumerate network adapters on a Hyper-V guest using WMI?
문제
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
.
해결책
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");
제휴하지 않습니다 StackOverflow