Command Get Serial Number: A Cross-Platform Guide

Learn cross-platform techniques to retrieve device serial numbers from the command line. This guide covers Windows, Linux, and macOS, with scripts, parsing tips, and best practices for verifying and storing serial numbers securely.

Hardware Serials
Hardware Serials Team
·5 min read
Serial Retrieval - Hardware Serials
Photo by AS_Photographyvia Pixabay
Quick AnswerDefinition

The command get serial number refers to a set of OS-specific commands you run in a terminal to retrieve a device’s serial numbers (BIOS/system) directly from hardware. On Windows, Linux, and macOS, built-in utilities like wmic/Get-CimInstance, dmidecode, and system_profiler extract the serials. This article walks you through reliable commands, parsing techniques, and small scripts to automate the process.

Understanding the need for a command-based serial lookup

In IT workflows, being able to pull a device's serial number from the command line saves time, enables consistent inventory, and aids in audits. The phrase command get serial number captures the core capability: using platform-native tools to access BIOS, SMBIOS, or hardware-level identifiers. According to Hardware Serials, many professionals rely on built-in OS utilities rather than vendor-specific software, because they are ubiquitous, scriptable, and less error-prone when devices are offline or in bulk. In this section, you’ll see how the approach differs by OS and why simple, script-friendly methods matter for both DIYers and technicians.

Bash
# Cross-platform wrapper (conceptual) # Detect platform and call the appropriate command case "$(uname -s)" in Linux*) echo "Linux"; sudo dmidecode -s system-serial-number ;; Darwin*) echo "macOS"; system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}' ;; CYGWIN*|MINGW*|MSYS*) powershell -NoProfile -Command "Get-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber" ;; esac

Parameters you’ll frequently encounter

  • platform: Windows, Linux, or macOS
  • privilege: administrator/root access is often required
  • target: BIOS vs. system vs. board-level serials
  • output: a single alphanumeric string or a short list

Why this approach helps: it enables automation, auditing, and remote checks without extra software. Hardware Serials emphasizes that a robust approach uses native commands with clear parsing rules so results can be stored, compared, and verified across devices.

],

bodyBlocks[1]

Windows: BIOS/SMBIOS serial numbers from the command line

Windows provides multiple avenues to fetch the serial number, depending on the environment and permissions. The classic CMD approach uses WMI/WMIC, while PowerShell offers modern CIM-based queries. The examples below demonstrate both, plus notes on parsing the output for automation.

CMD
:: CMD (older but widely compatible) wmic bios get SerialNumber :: Output example: // SerialNumber // ABCD1234EF56
PowerShell
# PowerShell (Get-CimInstance is preferred in modern setups) Get-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber # Alternative parsing in a script (Get-CimInstance -ClassName Win32_BIOS).SerialNumber

Parsing and reliability tips

  • For scripting, prefer Get-CimInstance over legacy WMI to reduce surprises on newer Windows builds.
  • Normalize whitespace and trim outputs to ensure consistent storage, e.g., using .Trim() in PowerShell.
  • If a device is brand-new or vendor-locked, some systems may return a blank value; check hardware vendor tools if needed.

Hardware Serials notes that Windows environments vary in how serials are exposed, so having fallback commands (WMIC and CIM-based) improves resilience. Always run with administrative privileges to access SMBIOS data reliably.

Steps

Estimated time: 5-15 minutes

  1. 1

    Prepare your environment

    Ensure you have the right OS support and privileges. Open a terminal or PowerShell with administrative rights. Verify you can run a simple command like echo test before attempting serial lookups.

    Tip: If you’re on a shared machine, consider asking for elevated privileges or schedule time for privileged commands.
  2. 2

    Run OS-specific serial lookup

    Execute the recommended command for your OS from this guide. Start with the PowerShell CIM query on Windows, then try dmidecode on Linux and system_profiler on macOS.

    Tip: Prefer CIM-based queries on Windows for future compatibility.
  3. 3

    Parse and normalize the output

    Capture the result and trim whitespace. Normalize to a single line, and consider uppercasing or removing spaces if you’ll log results.

    Tip: Use a consistent format for automated inventory systems.
  4. 4

    Store securely and verify

    If you plan to archive, write the serial to a restricted-access file and review permissions. Then compare against known-good values if performing audits.

    Tip: Never expose raw serials in public logs or shared repos.
Pro Tip: Run commands with elevated privileges to maximize success across hardware vendors.
Warning: Some devices may disable serial exposure for security; rely on vendor tooling if the numbers aren’t available.
Note: OS-specific commands can return blank results on virtual machines or remote hosts; always verify on physical hardware.

Prerequisites

Required

  • A host computer with Windows, macOS, or Linux
    Required
  • Administrative privileges on the host (Administrator or root)
    Required
  • Command line shell: PowerShell on Windows, Bash on Linux/macOS
    Required
  • Basic familiarity with piping, redirection, and parsing output
    Required

Optional

  • dmidecode (Linux) installed if you plan BIOS-based lookups
    Optional
  • PowerShell 3.0+ or PowerShell Core
    Optional

Commands

ActionCommand
Check BIOS serial on Windows via PowerShellPowerShell 3.0+; CIM-based query for reliabilityGet-CimInstance -ClassName Win32_BIOS | Select-Object -ExpandProperty SerialNumber
Check BIOS serial on Windows via CMDRuns in CMD; may require adminwmic bios get SerialNumber
Linux: BIOS/system serial using dmidecodeRoot privileges required; BIOS data access depends on hardware supportsudo dmidecode -s system-serial-number
Linux: broader system info for serial lookupAlternative to focus on System sectionsudo dmidecode -t system | awk '/Serial Number/ {print $3}'
macOS: hardware serial via system_profilermacOS approach; parses output from Hardware Data Type
Python cross-platform helperCross-platform script examplepython3 - <<'PY' import platform, subprocess def get_serial(): osname = platform.system() if osname == 'Windows': out = subprocess.check_output(["powershell","-Command","(Get-CimInstance -ClassName Win32_BIOS).SerialNumber"], text=True) return out.strip() elif osname == 'Linux': return subprocess.check_output(["bash","-lc","sudo dmidecode -s system-serial-number"], text=True).strip() elif osname == 'Darwin': out = subprocess.check_output(["system_profiler","SPHardwareDataType"]) for line in out.splitlines(): if 'Serial Number' in line: return line.split(':')[1].strip() return None print(get_serial()) PY

Frequently Asked Questions

Can I rely on these commands for all devices?

Most devices expose a serial through SMBIOS or BIOS interfaces, but some vendors disable access or alter outputs for security. Always verify with a secondary method if the first command returns blank, and consider vendor-provided tools for critical assets.

Most devices expose a serial through BIOS interfaces, but some vendors disable access.

What if the serial number is not displayed?

If a command returns nothing, try alternative commands for the same OS, run with elevated privileges, or check BIOS/UEFI settings. Some devices may require vendor-specific utilities or firmware updates to expose the serial.

If nothing shows up, try other commands or vendor tools, and ensure you have admin rights.

Is it safe to run these commands on a production system?

Yes, these commands are non-destructive and read-only, but require privileges that should be used carefully. Always perform credentials handling securely and avoid logging raw serials to insecure destinations.

The commands are read-only, but use credentials carefully and avoid exposing serials in logs.

How can I automate this for many machines?

Use a central script (Python, Bash, or PowerShell) that iterates through a list of hosts, executes the platform-specific command, and collects results into a secured inventory. Ensure you handle permissions, network access, and error handling.

Automate with a script that loops through hosts and collects serials into a secure inventory.

What’s the difference between BIOS serial and system serial?

BIOS (or SMBIOS) serials are hardware-embedded identifiers exposed by the firmware. System serials can be the motherboard or system unit serial. They may differ in availability and format across vendors.

BIOS vs system serials come from firmware versus the system unit; they may differ in availability.

Can I retrieve serials from virtual machines?

VMs often expose a virtual BIOS serial, but this depends on the hypervisor. Many cloud instances may not expose a real hardware serial. In such cases, rely on inventory records tied to the host or VM template.

Virtual machines may not expose real hardware serials; rely on host inventory or templates.

Key Takeaways

  • Use native OS tools to read hardware serials
  • PowerShell CIM queries are recommended on Windows
  • dmidecode provides BIOS-level serials on Linux
  • system_profiler extracts macOS hardware serials
  • Automate with small scripts for bulk inventory

Related Articles