🐍 Python 3.10+

Get Printers Report (Python)

Uses wmic under the hood to report Printers (Win32_Printer) — no third-party packages required.

By WindowsScripting.com · 1 KB
get_printer_report.py
#!/usr/bin/env python3
"""
get_printer_report.py

Reports Printers on this computer via WMI (Win32_Printer), using the
built-in `wmic` command so no extra packages are required.

Usage:
    python get_printer_report.py
"""

import csv
import io
import subprocess
import sys


def main() -> None:
    result = subprocess.run(
        ["wmic", "path", "Win32_Printer", "get", "Name,DriverName,PortName,PrinterStatus", "/format:csv"],
        capture_output=True, text=True, check=False,
    )

    if result.returncode != 0:
        sys.exit(f"wmic failed: {result.stderr.strip()}")

    lines = [line for line in result.stdout.splitlines() if line.strip()]
    if len(lines) < 2:
        print("No Printers found.")
        return

    reader = csv.DictReader(io.StringIO("\n".join(lines)))
    rows = list(reader)

    for row in rows:
        for key, value in row.items():
            if key and key != "Node":
                print(f"  {key}: {value}")
        print("-" * 40)

    print(f"\n{len(rows)} Printers found.")


if __name__ == "__main__":
    main()