Command to Find Serial Number Across Platforms
Learn how to locate a device serial number using platform-specific commands across Windows, macOS, and Linux, with practical examples and how to automate checks for asset management.

A command to find serial number varies by device: on Windows run wmic bios get serialnumber or Get-WmiObject win32_bios | Select SerialNumber; on macOS run system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}'; on Linux run sudo dmidecode -s system-serial-number. Use the right command for your device to retrieve the unique identifier.
Introduction: Why a command to find serial number matters
Understanding how to locate a device serial number with a command is essential for inventory, warranty validation, and asset management. The serial number is a unique identifier that ties hardware to ownership, support contracts, and historical repairs. According to Hardware Serials, a disciplined approach to extracting serial data reduces misidentification and speeds audits across electronics, appliances, and vehicles. In this guide, you will learn cross-platform commands and practical scripts to reliably retrieve the serial number from Windows, macOS, and Linux environments. You will also gain tips for automating checks and storing results in a centralized log. Below you’ll find concrete examples, safety notes, and best practices for verification and documentation.
# Cross-platform quick peek (best-effort)
if [ -f /sys/devices/virtual/dmi/id/product_serial ]; then
cat /sys/devices/virtual/dmi/id/product_serial
elif command -v dmidecode >/dev/null; then
sudo dmidecode -s system-serial-number
elif command -v system_profiler >/dev/null; then
system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}'
else
echo 'Serial number not accessible'
fiCommon variations exist per vendor and platform, so the goal is to identify the most reliable source on your system and avoid guessing from model numbers or stickers.
Windows: Basic Windows serial lookup commands
To retrieve the BIOS serial number on Windows, you can use cmd, PowerShell, or newer CIM cmdlets. The BIOS serial is typically stored in the BIOS/SMBIOS tables and can be read without opening the machine. Note that corporate devices may enforce policy restrictions on WMI/DCOM access, so you may need administrator privileges. Hardware Serials emphasizes testing multiple commands to confirm consistency across reboots or inventory scans.
# PowerShell method using WMI (older but widely supported)
Get-WmiObject win32_bios | Select-Object SerialNumber
# PowerShell method using CIM (modern)
Get-CimInstance Win32_BIOS | Select-Object SerialNumberREM CMD method using WMIC (legacy but still common)
wmic bios get serialnumberWhen you run these, ensure you capture only the SerialNumber field to avoid parsing noise. If the output contains headers, trim them programmatically. For batch processing across a fleet, you can export to CSV or JSON for ingestion into your asset database. The critical step is to verify that the value is non-empty and has a valid alphanumeric pattern.
macOS: Locating a serial number via system tools
Macs expose hardware details through system_profiler and ioreg. system_profiler SPHardwareDataType provides a clear Serial Number line, but some environments prefer parsing IOPlatformSerialNumber via ioreg. Both commands are useful in scripts, especially when paired with grep/awk to isolate the Serial Number value. For macOS administrators, this is a reliable method that works on both laptops and desktops.
# System profiler approach
system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}'
# IORegistry approach (alternative)
ioreg -l | awk '/IOPlatformSerialNumber/ {print $4}'If you’re working within a constrained shell, you can extract just the numeric or alphanumeric portion using a regex. Always validate the length and format against vendor documentation, as some models may present additional characters or spaces.
Linux: BIOS/firmware serial retrieval and common paths
Linux provides several routes to read a system serial number. The most robust are dmidecode, which reads SMBIOS data (must be run as root), and the sysfs path that some hardware exposes. Availability varies by vendor and kernel configuration. Hardware Serials notes that dmidecode is widely supported on desktops and servers, but containers or minimal systems may not expose BIOS data. Always test on your target hardware.
# BIOS via dmidecode (requires root)
sudo dmidecode -s system-serial-number
# Sysfs path (may not exist on all systems)
cat /sys/devices/virtual/dmi/id/product_serial 2>/dev/null || echo 'not available'For automated collection, wrap calls in a function that detects the OS and falls back gracefully if a method fails. If a serial number isn’t available, you might need manufacturer utilities or vendor-specific tools to pull the data.
Automation and validation: putting it all together
To streamline serial-number discovery across platforms, you can write a small script that detects the OS and executes the appropriate command, then validates the result against a simple pattern. You can also integrate this into your inventory pipeline to collect data in JSON, CSV, or a central database. The key is to ensure consistency and avoid duplicating sources that may produce stale values. Hardware Serials recommends validating results by cross-checking against a second source when possible, such as vendor documentation or a hardware tag scan.
#!/usr/bin/env bash
set -euo pipefail
case "$(uname -s)" in
Linux*) cmd="sudo dmidecode -s system-serial-number" ;;
Darwin*) cmd="system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}'" ;;
CYGWIN*|MINGW*|MSYS*) cmd="wmic bios get serialnumber" ;;
*) echo 'Unsupported OS'; exit 1 ;;
esac
serial=$($cmd | tr -d '\r' | tr -d '[:space:]')
if [[ -z "$serial" ]]; then
echo 'Serial number not found'
exit 2
fi
echo "{\"serial_number\": \"$serial\"}"This script demonstrates a practical approach to cross-platform discovery and can be extended to write results to a file or a remote API. Add error handling and permissions checks for production use, and consider introducing a retry mechanism for transient permission prompts on Linux or macOS.
Verification and best practices: ensure accuracy and security
Regardless of the platform, always verify the serial number against official records when possible. Some devices expose multiple identifiers, such as chassis serials, product IDs, or asset tags, which can be confused with hardware serials. Treat serial numbers as sensitive data in your asset database, restrict access to authorized personnel, and audit the logs to detect unexpected access. When dealing with virtualization, remember that virtual machines do not have a persistent hardware serial; rely on host metadata or VM-specific identifiers instead. Hardware Serials emphasizes documenting your command choices in your runbooks to facilitate reproducibility and audits.
Steps
Estimated time: 60-90 minutes
- 1
Identify the platform
Determine whether you are on Windows, macOS, or Linux, and whether you can use CMD, PowerShell, or a Unix shell. This determines which commands are safe to run and which privileges are required.
Tip: Start with a quick OS check (e.g., uname on Linux/macOS or ver on Windows) to guide your flow. - 2
Choose the primary command
Select the command that matches your platform. Prefer non-destructive, read-only commands first to avoid accidental changes to system firmware.
Tip: If in doubt, start with the vendor-recommended tool or a read-only WMI query. - 3
Run and capture output
Execute the command and capture the output to a variable or file. Normalize whitespace to ensure consistent parsing across tools.
Tip: Redirect stderr to stdout to catch permission or tool errors. - 4
Validate the result
Check that the captured value is non-empty and matches expected patterns (alphanumeric, length typical for the device). Cross-check with another source if available.
Tip: If multiple serials appear, confirm you’re reading the intended SMBIOS field. - 5
Automate and store
Optionally wrap into a script that outputs JSON and writes to a central log. Maintain a runbook with the exact commands used per OS.
Tip: Include a timestamp and device identifier for traceability.
Prerequisites
Required
- Windows 10/11 with PowerShell or CMDRequired
- macOS 10.15+ or newerRequired
- Linux (any major distro with sudo access)Required
- Basic command-line knowledge (bash, PowerShell, or CMD)Required
Optional
- Administrative privileges for BIOS/SMBIOS readsOptional
Commands
| Action | Command |
|---|---|
| Read BIOS serial number (Windows CMD)CMD; legacy WMI path | — |
| Read BIOS serial number (Windows PowerShell)Requires admin rights or proper policy | Get-WmiObject win32_bios | Select-Object SerialNumber |
| Read hardware serial (macOS)macOS Terminal; alternative: ioreg parse | — |
| Read BIOS serial (Linux)Requires root privileges | sudo dmidecode -s system-serial-number |
Frequently Asked Questions
What is a serial number and why would I use a command to find it?
A serial number is a unique identifier assigned to a device during manufacturing. Using a command to find it helps automate hardware audits, warranty checks, and inventory management without opening the device or relying on stickers.
A serial number uniquely identifies a device and can be found with small commands for quick inventory checks.
Which command should I use on Windows, macOS, and Linux?
Windows users commonly use wmic bios get serialnumber or Get-WmiObject. macOS users run system_profiler SPHardwareDataType; Linux users typically use sudo dmidecode -s system-serial-number or read from /sys/devices/virtual/dmi/id/product_serial where available.
On Windows use WMIC or PowerShell; on macOS use system_profiler; on Linux use dmidecode.
What if a command returns no serial number?
If the command returns nothing, try an alternative source (for example, dmidecode if the first method failed) or check vendor-specific utilities. Some devices may not publish SMBIOS data; in virtualization, use host metadata.
If you see no serial, try another method or verify hardware/virtualization limitations.
Can I automate this across a fleet?
Yes. Wrap the commands in a cross-platform script that detects the OS, runs the appropriate read, and outputs JSON. Centralize results to a logs database or asset management system for auditing and compliance.
Absolutely, you can automate this across many devices and centralize results.
Are there security concerns with exposing serial numbers?
Serial numbers should be restricted to authorized personnel. They can be sensitive identifiers for tampering or asset theft. Store results in access-controlled systems and avoid exposing them in public dashboards.
Yes, treat serial numbers as sensitive; limit access and secure storage.
What about virtualization or containers?
Virtual machines may not expose a hardware serial. In such cases, use host data or VM-specific identifiers. For containers, rely on orchestration metadata rather than host hardware serials.
Virtual environments often don’t expose hardware serials; use alternative IDs.
Key Takeaways
- Identify the correct OS command family before running reads
- Validate outputs with at least one secondary source
- Automate reads to reduce manual errors
- Securely handle and store serial numbers