Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes
Sponsored Reserved space — layout preview until AdSense is connected

Automatically Generate Hardware Inventory Reports in Python

Generate a system hardware report including OS version, CPU cores, RAM, and disk usage using platform and psutil.

Easy Python 3.9+ Jun 28, 2026 Automation & scripting 2 views 0 copies

Requires third-party packages — install first
pip install psutil

Python code

18 lines
Python 3.9+
import platform
import psutil  # requires: pip install psutil
from datetime import datetime

def generate_hardware_report():
    report_lines = []
    report_lines.append(f"Report Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    report_lines.append(f"System: {platform.system()} {platform.release()} ({platform.version()})")
    report_lines.append(f"Processor: {platform.processor()}")
    report_lines.append(f"CPU Cores: {psutil.cpu_count(logical=False)} physical, {psutil.cpu_count(logical=True)} logical")
    report_lines.append(f"Total RAM: {psutil.virtual_memory().total / (1024**3):.2f} GB")
    disk_info = psutil.disk_usage('/')
    report_lines.append(f"Disk (/): {disk_info.total / (1024**3):.2f} GB total, {disk_info.free / (1024**3):.2f} GB free")
    report_lines.append("-" * 40)
    return "\n".join(report_lines)

if __name__ == "__main__":
    print(generate_hardware_report())

Output

stdout
Report Generated: 2025-04-07 14:30:22
System: Windows 10 (10.0.19045)
Processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
CPU Cores: 4 physical, 8 logical
Total RAM: 15.86 GB
Disk (/): 237.43 GB total, 112.78 GB free
----------------------------------------

How it works

This script uses platform (stdlib) to capture OS and processor details and psutil (third-party) for hardware resource data. datetime stamps the report. The function assembles a formatted string with each hardware metric on its own line.

Common mistakes

  • Forgetting to install psutil via pip before running the code.
  • Assuming disk path '/' works on Windows — on that OS use the drive letter like 'C:' .
  • Calling psutil virtual memory methods on unsupported platforms without a fallback.

Variations

  1. Export the report as a plain-text file instead of printing it.
  2. Add network interface info with `psutil.net_if_addrs()` for more complete inventory.

Real-world use cases

  • Generating a daily inventory report for IT asset management across a fleet of servers.
  • Checking hardware specs on a remote machine before deploying a resource-heavy application.
  • Collecting system telemetry from developer workstations for capacity planning.

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Run locally

This sample needs third-party packages, so it cannot run in the browser IDE. Copy the code above, install the packages shown at the top, then run it in your own Python environment.

More from Automation & scripting

Related tutorials and quizzes for this topic.