How to Get Network Adapter Hardware Details in Batch Script
For network troubleshooting, system inventory, or configuration scripting, you often need to get detailed hardware information about the network interface cards (NICs) installed in a computer. This includes essential details like the MAC Address, the product name, and the manufacturer. This information is available through the Windows Management Instrumentation (WMI) framework.
This guide will teach you how to use the built-in WMIC (Windows Management Instrumentation Command-line) utility to query the system for detailed properties of all network adapters. You will learn the correct WMI alias to use and how to create a useful inventory report from your batch script.
The Core Command: WMIC NIC GET
The WMIC utility is the standard tool for querying system hardware. The NIC (Network Interface Controller) alias provides a direct interface to the Win32_NetworkAdapter WMI class.
Syntax: WMIC NIC GET <Property1,Property2,...>
WMIC: The command-line utility.NIC: The alias for network adapters.GET ...: The specific properties we want to retrieve.
Key Network Adapter Properties Explained
Name: The user-friendly name of the adapter (e.g., "Intel(R) Ethernet Connection I219-LM").Description: Often the same asName.Manufacturer: The name of the hardware manufacturer (e.g., "Intel").MACAddress: The unique, physical hardware address of the adapter.NetConnectionID: The name of the connection as seen in the "Network Connections" control panel (e.g., "Ethernet", "Wi-Fi").AdapterType: The type of adapter (e.g., "Ethernet 802.3").Speed: The link speed of the connection in bits per second (e.g.,1000000000for 1 Gbps).
Basic Example: Displaying All Adapter Details
You can run this command directly to see a list of all network adapters and their key properties.
@ECHO OFF
ECHO --- Querying Network Adapter Details ---
ECHO.
WMIC NIC GET Name, Manufacturer, MACAddress, NetConnectionID
The output from WMIC is a table listing each detected network adapter.
--- Querying Network Adapter Details ---
MACAddress Manufacturer Name NetConnectionID
...
00:1A:2B:3C:4D:5E Intel Intel(R) Ethernet Connection I219-LM Ethernet
A1:B2:C3:D4:E5:F6 Intel Intel(R) Dual Band Wireless-AC 8265 Wi-Fi
...
How to Capture the Information in a Script
To use this data, you should have WMIC format the output as CSV and then parse it with a FOR /F loop. This is the most reliable way to handle adapter names that contain spaces.
@ECHO OFF
SETLOCAL
ECHO --- Capturing a List of All Network Adapters ---
ECHO.
REM 'skip=1' ignores the header. 'tokens=2-5' grabs the four data columns.
FOR /F "skip=1 tokens=2,3,4,5 delims=," %%A IN (
'WMIC NIC GET MACAddress,Manufacturer,Name,NetConnectionID /FORMAT:CSV'
) DO (
ECHO Found Adapter:
ECHO Connection Name: "%%~D"
ECHO Model: "%%~C"
ECHO Manufacturer: "%%~B"
ECHO MAC Address: "%%~A"
ECHO.
)
ENDLOCAL
The ~ modifier (%%~A) is used to remove the quotes that the CSV format adds.
How the WMIC NIC Method Works
The WMIC NIC command is an interface to the WMI service. It queries the Win32_NetworkAdapter class, which represents a physical or logical network adapter. WMI reads this information directly from the Windows Plug and Play manager and the network device drivers, making it an authoritative source for hardware details.
Common Pitfalls and How to Solve Them
Problem: The List Includes Virtual Adapters
The WMIC NIC query returns every network interface known to Windows, not just the physical ones. This includes:
- Virtual adapters for VPNs (e.g., WAN Miniport).
- Adapters for virtual machine software (e.g., Hyper-V, VMware).
- Bluetooth adapters.
- Loopback adapters.
Solution: For most inventory tasks, you only care about physical Ethernet or Wi-Fi adapters. You can filter the WMI query with a WHERE clause.
REM This query returns only physical adapters that are currently enabled.
WMIC NIC WHERE "AdapterTypeID='0' AND NetConnectionStatus='2'" GET Name, MACAddress
AdapterTypeID='0'corresponds to Ethernet 802.3.NetConnectionStatus='2'corresponds to a "Connected" state.
Problem: Parsing the WMIC Output
The default table format of WMIC is difficult to parse reliably.
Solution: Always use the /FORMAT:CSV switch when you intend to capture WMIC output in a script. It makes parsing with FOR /F simple and robust.
Practical Example: A Network Hardware Report
This script uses the robust CSV format and a WHERE clause to create a clean report of only the primary physical network adapters.
@ECHO OFF
SETLOCAL
SET "ReportFile=%USERPROFILE%\Desktop\Network_Hardware_Report.csv"
ECHO --- Network Hardware Inventory Script ---
ECHO Creating report at: "%ReportFile%"
REM --- Create the CSV Header ---
(ECHO "NetConnectionID","Name","Manufacturer","MACAddress","Speed_Mbps") > "%ReportFile%"
REM --- Get the data from WMIC, filtering for physical adapters ---
FOR /F "skip=1 tokens=2,3,4,5,6 delims=," %%A IN (
'WMIC NIC WHERE "PhysicalAdapter=True" GET MACAddress,Manufacturer,Name,NetConnectionID,Speed /FORMAT:CSV'
) DO (
SET "SpeedBps=%%E"
REM Convert speed from bps to Mbps if it's defined
SET "SpeedMbps=N/A"
IF DEFINED SpeedBps (
FOR /F %%S IN ('powershell -Command "!SpeedBps! / 1000000"') DO SET "SpeedMbps=%%S"
)
ECHO "%%~D","%%~C","%%~B","%%~A","!SpeedMbps!" >> "%ReportFile%"
)
ECHO.
ECHO [SUCCESS] Report created.
START "" "%ReportFile%"
ENDLOCAL
Note the powerful WHERE "PhysicalAdapter=True" clause, which is the easiest way to filter out virtual adapters.
Conclusion
The WMIC NIC command is the standard, built-in method for retrieving detailed hardware information about network adapters from a batch script.
Key takeaways:
- Use
WMIC NIC GET <Properties>to query adapter details. - For scripting, always use
/FORMAT:CSVto make parsing easy and reliable. - Use a
WHEREclause (e.g.,WHERE "PhysicalAdapter=True") to filter the list and exclude virtual or unwanted adapters. - Use a
FOR /Floop to capture and process the information for each adapter found.