MSFT_NetAdapter无MACAddress属性,Win32_NetworkAdapter已弃用,如何获取MAC地址?
Nice question! I remember being confused by this too when Microsoft deprecated Win32_NetworkAdapter in favor of the newer MSFT_NetAdapter classes. Let's clear this up:
First off: MSFT_NetAdapter does not have a direct MACAddress property—that's the key source of confusion here. Microsoft split hardware-specific attributes (like MAC addresses) into a separate class to keep MSFT_NetAdapter focused on configuration and state. Here are the reliable ways to get the MAC address:
1. Query via CIM, linking MSFT_NetAdapter and MSFT_NetAdapterHardwareInfo
The MSFT_NetAdapter and MSFT_NetAdapterHardwareInfo classes are linked by the InstanceID property. You can use WQL or PowerShell's CIM cmdlets to join them and retrieve the MAC:
WQL Example
SELECT MSFT_NetAdapter.Name, MSFT_NetAdapterHardwareInfo.PermanentAddress FROM MSFT_NetAdapter JOIN MSFT_NetAdapterHardwareInfo ON MSFT_NetAdapter.InstanceID = MSFT_NetAdapterHardwareInfo.InstanceID
PermanentAddress here maps directly to the MACAddress property from the old Win32_NetworkAdapter class—it's the physical, permanent MAC of the adapter.
PowerShell CIM Example
Get-CimInstance MSFT_NetAdapter | ForEach-Object { $hardwareDetails = Get-CimInstance MSFT_NetAdapterHardwareInfo -Filter "InstanceID='$($_.InstanceID)'" [PSCustomObject]@{ AdapterName = $_.Name MACAddress = $hardwareDetails.PermanentAddress } }
2. Use PowerShell's Get-NetAdapter Cmdlet (Simplest Option)
If you're working in PowerShell, this is the easiest path. The Get-NetAdapter cmdlet wraps the CIM class logic and exposes a direct MacAddress property:
Get-NetAdapter | Select-Object Name, MacAddress
This will output a clean list of all your adapters with their corresponding MAC addresses—no manual class joining required.
Why the Split?
Microsoft redesigned the network adapter CIM classes to separate concerns:
MSFT_NetAdapterhandles adapter configuration (like IP settings, enabled state) and general state.MSFT_NetAdapterHardwareInfoholds hardware-specific details (MAC address, firmware version, bus type).
This makes the classes more modular and easier to maintain.
内容的提问来源于stack exchange,提问作者ispiro

