Skip to main content

How to Get the Speed and Duplex of a Network Adapter in Batch Script

A Gigabit network card is only useful if it's actually running at Gigabit speeds. If your adapter has auto-negotiated to 100Mbps or 10Mbps (often due to a damaged cable or a bad switch port), your entire office connection will feel sluggish. Identifying the current "Link Speed" and "Duplex" (Full vs. Half) is the first step in hardware troubleshooting. A Batch script can use WMIC or PowerShell to query the physical link characteristics of your network card, ensuring it is operating at its maximum potential.

This guide will explain how to audit adapter speed and duplex settings.

Method 1: Using WMIC (Direct Speed Query)

The Win32_NetworkAdapter class provides the raw Speed property in bits per second.

note

WMIC has been deprecated starting in Windows 11. See Method 2 for a forward-compatible PowerShell alternative.

@echo off
setlocal enabledelayedexpansion

set "AdapterName=Ethernet"

echo [AUDIT] Checking Link Speed for "%AdapterName%"...
echo.

:: Verify the adapter exists
set "found=0"
for /f "tokens=2 delims==" %%n in ('wmic nic get NetConnectionID /value 2^>nul') do (
for /f "delims=" %%m in ("%%n") do (
if /i "%%m"=="%AdapterName%" set "found=1"
)
)

if !found! equ 0 (
echo [ERROR] Adapter "%AdapterName%" not found.
echo.
echo Available adapters:
wmic nic where "NetConnectionID is not null" get NetConnectionID 2>nul
pause
endlocal
exit /b 1
)

:: Query for Speed in bits per second
:: Nested FOR strips invisible \r from WMIC output
set "raw_speed="
for /f "tokens=2 delims==" %%a in ('wmic nic where "NetConnectionID='%AdapterName%'" get Speed /value 2^>nul') do (
for /f "delims=" %%b in ("%%a") do set "raw_speed=%%b"
)

:: Validate
if not defined raw_speed (
echo [ERROR] Could not retrieve speed. Adapter may be disconnected.
pause
endlocal
exit /b 1
)

:: Convert to Mbps using string manipulation
:: Batch set /a overflows above 2,147,483,647, a 10Gbps link (10000000000) would crash
:: Instead, slice off the last 6 digits to divide by 1,000,000
set "speed_len=0"
set "temp=!raw_speed!"
:CountLen
if defined temp (
set "temp=!temp:~1!"
set /a speed_len+=1
goto :CountLen
)

if !speed_len! gtr 6 (
set /a trim=!speed_len!-6
set "mbps=!raw_speed:~0,%%trim%%!"
:: Use PowerShell for reliable division since batch string math is fragile
for /f %%m in ('powershell -NoProfile -Command "[math]::Round(%raw_speed% / 1000000)"') do set "mbps=%%m"
) else (
set "mbps=0"
)

echo [RESULT] %AdapterName% Link Speed: !mbps! Mbps (!raw_speed! bps^)
echo.

:: Warn if below Gigabit
if !mbps! lss 1000 (
if !mbps! gtr 0 (
echo [WARNING] Adapter is NOT running at Gigabit speed!
echo Possible causes: damaged cable, bad switch port, or auto-negotiation issue.
)
) else (
echo [OK] Adapter is running at Gigabit speed or higher.
)

pause
endlocal
Why not use set /a for division?

Batch arithmetic overflows at 2,147,483,647. A 1Gbps link reports 1000000000 (just under the limit), but a 10Gbps link reports 10000000000, which crashes set /a silently. Using string manipulation or PowerShell for the conversion avoids this limitation.

Method 2: High-Detail Audit (PowerShell Bridge)

WMIC doesn't easily show "Duplex" (Full vs. Half). PowerShell's Get-NetAdapter provides a much cleaner, more complete summary including duplex mode and media type.

@echo off
setlocal

echo [REPORT] Detailed Network Link Capabilities...
echo.

powershell -NoProfile -Command ^
"$adapters = Get-NetAdapter -ErrorAction SilentlyContinue;"^
"if (-not $adapters) {"^
" Write-Host '[ERROR] No network adapters found.';"^
" exit 1"^
"};"^
"Write-Host (' {0,-45} {1,-12} {2,-15} {3,-12} {4}' -f 'ADAPTER','STATUS','LINK SPEED','DUPLEX','MEDIA TYPE');"^
"Write-Host (' ' + '-' * 100);"^
"$warnings = 0;"^
"foreach ($a in $adapters) {"^
" $icon = if ($a.Status -eq 'Up') { '[OK]' } else { '[--]' };"^
" $speed = if ($a.LinkSpeed) { $a.LinkSpeed } else { 'N/A' };"^
" $duplex = if ($null -ne $a.FullDuplex) { if ($a.FullDuplex) { 'Full' } else { 'Half' } } else { 'N/A' };"^
" $media = if ($a.MediaType) { $a.MediaType } else { 'N/A' };"^
" Write-Host (' {0} {1,-40} {2,-12} {3,-15} {4,-12} {5}' -f $icon, $a.Name, $a.Status, $speed, $duplex, $media);"^
" if ($a.Status -eq 'Up' -and $a.FullDuplex -eq $false) {"^
" Write-Host ' ^^^ [WARNING] Half Duplex detected - performance will be degraded!' -ForegroundColor Yellow;"^
" $warnings++"^
" };"^
" if ($a.Status -eq 'Up' -and $a.LinkSpeed -match '100 Mbps|10 Mbps') {"^
" Write-Host ' ^^^ [WARNING] Sub-Gigabit speed - check cable and switch port!' -ForegroundColor Yellow;"^
" $warnings++"^
" }"^
"};"^
"Write-Host (' ' + '-' * 100);"^
"if ($warnings -gt 0) {"^
" Write-Host '';"^
" Write-Host (' ' + $warnings + ' warning(s) found. Investigate flagged adapters.') -ForegroundColor Yellow"^
"} else {"^
" Write-Host '';"^
" Write-Host ' All active adapters are running at optimal speed and duplex.' -ForegroundColor Green"^
"}"

pause
endlocal
Why PowerShell for duplex?

WMIC's Win32_NetworkAdapter class does not expose a duplex property. The only reliable way to check Full vs. Half Duplex is through PowerShell's Get-NetAdapter cmdlet, which reads directly from the network driver.

Method 3: Visual Diagnostic for All Enabled Adapters

A quick overview of all enabled adapters and their speeds, with proper formatting.

@echo off
setlocal EnableDelayedExpansion

echo [NIC SUMMARY] All enabled network adapters
echo.

set "found=0"

:: Column width
set "nameW=40"
set /a truncW=nameW-3

echo ADAPTER NAME SPEED (bps^)
echo ================================================================

for /f "skip=2 tokens=2,3 delims=," %%A in ('wmic nic where "NetEnabled=True" get Name^,Speed /format:csv 2^>nul') do (

set "adName=%%A"
set "adSpeed=%%B"

if defined adName if defined adSpeed (

:: Trim leading spaces
for /f "tokens=* delims= " %%X in ("!adName!") do set "adName=%%X"

:: Truncate safely (FIXED)
if "!adName:~%nameW%,1!" NEQ "" (
set "adName=!adName:~0,%truncW%!..."
)

:: Pad for alignment
set "spaces= "
set "paddedName=!adName!!spaces!"
set "paddedName=!paddedName:~0,%nameW%!"

echo !paddedName! !adSpeed!
set "found=1"
)
)

echo ================================================================

if !found! equ 0 (
echo.
echo [WARN] No enabled adapters found.
)

pause
endlocal

Method 4: Fleet Audit (CSV Export for Multiple Machines)

For managing multiple computers, export speed and duplex data to a CSV file that can be collected centrally.

@echo off
setlocal

set "OutputFile=%USERPROFILE%\nic_audit_%COMPUTERNAME%.csv"

echo [AUDIT] Exporting adapter speed data to CSV...
echo File: %OutputFile%
echo.

powershell -NoProfile -Command ^
"$results = @();"^
"foreach ($a in (Get-NetAdapter -ErrorAction SilentlyContinue)) {"^
" $results += [PSCustomObject]@{"^
" Computer = $env:COMPUTERNAME;"^
" Adapter = $a.Name;"^
" Status = $a.Status;"^
" LinkSpeed = $a.LinkSpeed;"^
" FullDuplex = $a.FullDuplex;"^
" MediaType = $a.MediaType;"^
" MacAddress = $a.MacAddress"^
" }"^
"};"^
"$results | Export-Csv -Path '%OutputFile%' -NoTypeInformation;"^
"Write-Host ('[OK] Exported ' + $results.Count + ' adapter(s) to CSV.')"

pause
endlocal
Use case

Deploy this script as a logon task across your network. Collect the CSV files centrally and open them in Excel to quickly identify which desks have adapters running at sub-Gigabit speeds, a strong indicator of damaged cables or faulty switch ports.

How to Avoid Common Errors

Wrong Way: Assuming "Connected" Means "Fast"

A computer can show a green checkmark for "Internet Access" even if the link speed has dropped to 10Mbps.

Correct Way: Always query the LinkSpeed or Speed property. If you see 1000000000 (1Gbps) falling to 100000000 (100Mbps), you have a hardware problem, typically a damaged cable, bad switch port, or driver issue.

Wrong Way: Using set /a for Speed Conversion

Batch arithmetic overflows at 2,147,483,647. A 10Gbps link speed of 10000000000 will crash set /a silently, producing garbage output.

Correct Way: Use string manipulation to slice digits, or delegate the math to PowerShell:

for /f %%m in ('powershell -NoProfile -Command "[math]::Round(%raw_speed% / 1000000)"') do set "mbps=%%m"

Wrong Way: Using WMIC Output Without Stripping \r

WMIC appends invisible carriage return characters to every value. String comparisons and concatenation will fail silently.

Correct Way: Use a nested FOR /F to strip the trailing characters:

for /f "tokens=2 delims==" %%a in ('wmic ... /value') do (
for /f "delims=" %%b in ("%%a") do set "var=%%b"
)

Problem: Adapter Name Varies Between Machines

"Ethernet" on your machine might be "Ethernet 2," "Local Area Connection," or a vendor-specific name on another machine.

Solution: List available names first, or use Method 2/4 which enumerate all adapters automatically:

wmic nic where "NetConnectionID is not null" get NetConnectionID

Best Practices and Rules

1. Identify "Half Duplex"

If a card is running in Half Duplex, it can't send and receive at the same time, leading to massive performance drops during big file transfers. Use Method 2 to verify your card is in "Full Duplex" mode. Half Duplex on a modern network almost always indicates a cabling or switch configuration problem.

2. Administrator Privileges

Querying deep hardware properties of a network card usually requires running as an Administrator. PowerShell's Get-NetAdapter typically works without elevation for basic properties.

3. Log the "Slowdown"

If you manage multiple computers, have this script run as a logon task and save the results to a CSV (Method 4). It will help you spot desks with bad wall jacks that are forcing computers into 100Mbps mode.

4. WMIC Deprecation

Microsoft has deprecated WMIC starting in Windows 11. For forward-compatible scripts, use PowerShell's Get-NetAdapter (Method 2) or Get-CimInstance Win32_NetworkAdapter.

5. Speed Reference Table

Raw Speed (bps)Human ReadableExpected For
1000000010 MbpsLegacy / damaged cable
100000000100 MbpsFast Ethernet / degraded Gigabit
10000000001 GbpsStandard Gigabit Ethernet
25000000002.5 Gbps2.5G Ethernet
1000000000010 GbpsServer / high-performance

6. Always Use setlocal / endlocal

Without setlocal, every variable your script creates persists in the parent shell session, causing potential conflicts when running multiple scripts in sequence.

Conclusions

Auditing the speed and duplex of your network adapters is a critical part of professional hardware maintenance. By moving from a simple "Is it on?" check to a detailed speed verification, you ensure your infrastructure is delivering the bandwidth you paid for. This visibility allows you to identify failing cables and ports before they cause noticeable downtime, keeping your Windows environment fast, efficient, and reliable.