Skip to main content

How to List All Printer Ports in Batch Script

When you install a printer in Windows, it must be "Bound" to a communication port. This could be a physical port (like USB001, LPT1, or COM1), a virtual port (like WSD for discovery), or a network port (Direct IP). If a printer is "Connected" but won't print, the first place to look is the Port mapping. If a printer is accidentally bound to a deleted IP address or the wrong USB slot, it will never receive your data. A Batch script can use WMIC or PowerShell to generate a comprehensive map of all active ports, allowing you to audit your hardware connections instantly.

This guide will explain how to list and audit printer ports.

Method 1: The Quick Port List (WMIC)

WMIC provides a fast way to see every port name and its underlying host address or hardware identifier.

@echo off
echo [AUDIT] Identifying active printer ports...
echo.

echo --- TCP/IP Ports ---
wmic path Win32_TCPIPPrinterPort get Name, HostAddress 2>nul

if %errorlevel% neq 0 (
echo [INFO] No TCP/IP printer ports found.
)

echo.
echo --- All Ports (Local, USB, Network^) ---
wmic path Win32_PrinterPort get Name, Description 2>nul

if %errorlevel% neq 0 (
echo [INFO] No printer ports found.
)

echo.
pause

Method 2: Detecting "WSD" vs "Standard TCP/IP"

WSD (Web Services for Devices) is great for "Plug-and-Play," but it is notoriously unreliable for business printers because the port name changes if the printer's IP address changes.

@echo off
echo [SCAN] Checking for WSD discovery ports...
echo.

set "WSDFound=0"

for /f "skip=1 tokens=*" %%a in ('wmic path Win32_PrinterPort get Name 2^>nul ^| findstr /i "WSD"') do (
echo [WSD] %%a
set "WSDFound=1"
)

if "%WSDFound%"=="1" (
echo.
echo [WARNING] WSD ports detected. For high reliability,
echo convert these to Static TCP/IP ports.
) else (
echo [OK] No WSD ports found. All ports appear to be static.
)

echo.
pause

Method 3: PowerShell Inventory Export (Clean Report)

If you are a sysadmin documenting a server, PowerShell can export a clean CSV of every port and its configuration details.

@echo off
set "OutFile=%~dp0Printer_Port_Inventory.csv"

echo [REPORT] Exporting printer port metadata...

powershell -NoProfile -Command ^
"$ports = Get-PrinterPort -ErrorAction SilentlyContinue;" ^
"if (-not $ports) { Write-Host '[INFO] No printer ports found.'; exit };" ^
"$ports | Select-Object Name, Description, PrinterHostAddress, PortNumber |" ^
" Export-Csv -Path '%OutFile%' -NoTypeInformation;" ^
"Write-Host '[DONE] Audit saved to: %OutFile%';" ^
"Write-Host \"$($ports.Count) port(s) exported.\""

if %errorlevel% neq 0 (
echo [ERROR] Export failed. Ensure you are running as ADMIN.
)

pause

How to Avoid Common Errors

Wrong Way: Mistaking "Port Name" for "Printer Name"

A port might be named IP_10.0.0.50, but the printer using it might be named Warehouse_Zebra_1. If you try to delete the "Printer" to fix a connection, the "Port" will often stay in the system, potentially causing conflict when you try to reinstall.

Correct Way: Use Method 1 or 3 to see the Real Mapping. This tells you exactly which "Pipe" the data is traveling through, regardless of what the printer is named in the software.

Problem: WMIC Path Errors

If you type wmic printerport, it might return an error.

Solution: You must use the full class path wmic path Win32_PrinterPort (as shown in Method 1) to get the hardware-level data for non-USB ports.

Best Practices and Rules

1. Identify "Orphaned" Ports

Legacy ports that aren't attached to any printer take up system resources and clutter the driver menus. Use Method 3 to identify ports that have no "Associated Printer."

2. Standardize IPv4 Ports

For business-grade printers, always use the format IP_[Actual_IP_Address] for the port name. This makes troubleshooting 100% easier than names like Port_1 or New_Port_6.

3. Log During Maintenance

Log the port list whenever you change a hardware IP. This provides a "Historical Record" you can use if you need to roll back a configuration change. wmic path Win32_TCPIPPrinterPort get Name, HostAddress >> port_audit_log.txt

Conclusions

Listing all printer ports via Batch script is a fundamental step for professional Windows hardware management. By moving from the limited "Ports" tab in the GUI to automated command-line auditing, you gain the visibility needed to solve complex connectivity issues instantly. This professional level of oversight ensures that your communication channels stay clear and that your hardware mappings remain accurate and predictable across your entire infrastructure.