Hyper-V - Fetch Network-Adapter related information(MACAddress, Switch, Name, IPaddress) Through WMI query

MAHESH NIKAM 1 Reputation point
2020-10-22T15:11:53.557+00:00

I want to fetch following Virtual Machine related information through WMI:
Network Adapter:

  1. MACaddress
  2. IPaddress
  3. SwitchName
  4. Name

Same information I can fetch through powershell:

Get-VM -Id '{VM-ID}' | Get-VMNetworkAdapter | Select IPAddresses, SwitchName, MacAddress, Name

But I want to achieve same through WMI queries.

Please suggest me best approach

Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,547 questions
Windows Server Management
Windows Server Management
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Management: The act or process of organizing, handling, directing or controlling something.
421 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Laude 85,666 Reputation points
    2020-10-22T16:05:17.29+00:00

    Hi @MAHESH NIKAM ,

    I'm no WMI expert but these different commands below will get you the following:

    • IP addresses
    • Virtual Switch name
    • MAC Address
    • Network Adapter name

    Gets the network adapter name & MAC address of the Hyper-V guest virtual machine

    $VMName = "VMname"  
    $VMNet = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VMName'"  
    $VMNet.GetRelated('Msvm_SyntheticEthernetPort') | Select ElementName, PermanentAddress  
    

    Gets the Hyper-V switch name of the Hyper-V guest virtual machine

    $VMName = "VMname"  
    $VMSwitch = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VMName'"  
    $VMSwitch.GetRelated('Msvm_SummaryInformation') | Select VirtualSwitchNames  
    

    Gets the IP addresses of the Hyper-V guest virtual machine

    $VMName = "VMname"  
    $Msvm_VirtualSystemManagementService = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService   
    $Msvm_ComputerSystem = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VMName'"  
    $Msvm_VirtualSystemSettingData = ($Msvm_ComputerSystem.GetRelated("Msvm_VirtualSystemSettingData","Msvm_SettingsDefineState", $null, $null, "SettingData", "ManagedElement", $false, $null) | % {$_})  
    $Msvm_SyntheticEthernetPortSettingData = $Msvm_VirtualSystemSettingData.GetRelated("Msvm_SyntheticEthernetPortSettingData")  
    $Msvm_GuestNetworkAdapterConfiguration = ($Msvm_SyntheticEthernetPortSettingData.GetRelated("Msvm_GuestNetworkAdapterConfiguration"))  
    $Msvm_GuestNetworkAdapterConfiguration | Select IPAddresses  
    

    ----------

    (If the reply was helpful please don't forget to upvote or accept as answer, thank you)

    Best regards,
    Leon

    1 person found this answer helpful.