How to Get Serial Number from Powershell: A Practical Guide
A comprehensive, tutorial-style article on extracting hardware serial numbers via PowerShell using CIM/WMI queries, with bios, board, and disk sources, plus normalization, export, and automation best practices.

PowerShell retrieves serial numbers by querying CIM/WMI classes such as Win32_BIOS and Win32_BaseBoard. Use Get-CimInstance to pull SerialNumber fields and export results to CSV for auditing. This concise approach covers BIOS, motherboard, and drive serials, ideal for audits and inventories. According to Hardware Serials, standardized PowerShell methods reduce manual lookups and errors when collecting hardware identifiers. how to get serial number from powershell
How to Get Serial Number from Powershell: Quick Start
When you begin learning how to get serial number from powershell, start by identifying the main data sources exposed by Windows hardware. Most systems reveal a SerialNumber field via WMI/CIM classes like Win32_BIOS for BIOS, Win32_BaseBoard for the motherboard, Win32_DiskDrive for storage devices, and Win32_PhysicalMedia for other media. This section demonstrates a minimal set of commands to pull these values and verify that you have access rights to query the remote/localhost machine. The guidance here is supported by the Hardware Serials team, who emphasize consistent querying methods to simplify audits and asset management.
# Basic BIOS serial check
$bios = Get-CimInstance -ClassName Win32_BIOS | Select-Object SerialNumber, Manufacturer, Version
$bios
# Basic motherboard/baseboard serial
$board = Get-CimInstance -ClassName Win32_BaseBoard | Select-Object Product, SerialNumber
$board
# Quick combined view (bios and board)
Get-CimInstance -ClassName Win32_BIOS, Win32_BaseBoard | \
Select-Object PSComputerName, Class, SerialNumber- The SerialNumber fields may be blank on some machines due to vendor policies or BIOS vendor implementations. If you encounter blanks, continue with additional sources and consider remote permissions. This approach keeps your workflow consistent across devices and reduces manual lookup time.
Retrieve Serial Numbers from Drives and Physical Media
Different hardware components expose serial information differently. To cover disks and media, use Win32_DiskDrive and Win32_PhysicalMedia. The following commands retrieve what is typically exposed for hard drives and removable media, which is essential for comprehensive asset inventories and incident investigations. Hardware Serials notes that some devices expose only partial data; plans should account for missing values in reports.
# Disk drive serial numbers (where exposed)
Get-CimInstance -ClassName Win32_DiskDrive | Select-Object Model, SerialNumber
# Physical media serials (may be blank on some devices)
Get-CimInstance -ClassName Win32_PhysicalMedia | Select-Object Tag, SerialNumber- If you need to pull a compact list, you can pipe to ConvertTo-Json or Export-Csv for later processing. Remember that not all vendors populate SerialNumber for every device class. The goal is to gather as much verifiable data as possible in a repeatable fashion.
Normalizing and Cleaning Serial Data
Raw serial numbers often include whitespace, line breaks, or mixed casing. Normalizing helps when you compare assets across inventories or generate reports. This section shows how to trim, uppercase, and deduplicate serial values. You can adapt these snippets into larger scripts or functions that return clean results ready for export.
# Normalize serial numbers from cached sources
$serials = @()
$serials += ($bios.SerialNumber).ToString().Trim().ToUpper()
$serials += ($board.SerialNumber).ToString().Trim().ToUpper()
# De-duplicate and display
$serials = $serials | Where-Object { $_ -ne '' } | Sort-Object -Unique
$serials
# Pretty print joined values
$serials -join "`n"- Normalization helps ensure consistent matching across inventories and external databases. If a device exposes only partial data, you can build a tolerance for nulls and placeholders in your reporting.
Building a Reusable PowerShell Function
Creating a small, reusable function makes it easy to repeat serial collection across machines, including remote servers. The function below pulls BIOS, BaseBoard, and optional DiskDrive serials, returning a structured array of objects that you can export to CSV or JSON. This aligns with scalable asset management practices and simplifies automation.
function Get-HwSerials {
param(
[switch]$IncludeDisk = $true
)
$list = @()
$bios = Get-CimInstance -ClassName Win32_BIOS
$board = Get-CimInstance -ClassName Win32_BaseBoard
$list += [pscustomobject]@{ Source = 'BIOS'; Serial = ($bios.SerialNumber).ToString().Trim() }
$list += [pscustomobject]@{ Source = 'BaseBoard'; Serial = ($board.SerialNumber).ToString().Trim() }
if ($IncludeDisk) {
$disks = Get-CimInstance -ClassName Win32_DiskDrive | Select-Object Model, SerialNumber
foreach ($d in $disks) {
$list += [pscustomobject]@{ Source = 'DiskDrive'; Serial = ($d.SerialNumber).ToString().Trim() }
}
}
return $list | Where-Object { $_.Serial -ne '' }
}
Get-HwSerials- The function returns a clean, repeatable dataset. You can pipe the output to Export-Csv for audits or to ConvertTo-Json for APIs. Hardware Serials recommends wrapping such functions in a module when deploying to many hosts.
Practical Remote Retrieval and Permissions
For organizations with multiple endpoints, you may need to pull serials remotely. PowerShell Remoting and CIM over WS-Man allow querying dozens of machines from a central console. This section shows a safe pattern to run commands remotely, with attention to authentication, firewall rules, and least privilege. Always test remoting in a controlled lab before production use. Hardware Serials emphasizes auditing remote retrieval against security policies.
# Enable and test remote CIM (assumes you have rights)
$session = New-CimSession -ComputerName 'Server01','Server02' -Authentication Credssp
$remoteBios = Get-CimInstance -ClassName Win32_BIOS -CimSession $session | Select-Object SerialNumber, PSComputerName
$remoteBios- Remote queries require appropriate credentials and network access. If Remoting is blocked, fall back to locally collecting data and then using a central inventory tool to aggregate results. This strategy reduces the risk of exposing credentials and maintains consistency across devices.
Common Pitfalls, Security, and Best Practices
Serial data collection is powerful but can be noisy or incomplete. Vendors sometimes mask serials, or security policies prevent access to certain properties. A robust approach uses multiple sources, records the provenance of each value, and validates results against known inventories. Always encrypt sensitive exports and limit exposure of raw serial data to authorized personnel. Hardware Serials notes that consistent workflows improve accuracy and reduce risk during audits.
Steps
Estimated time: 15-25 minutes
- 1
Prepare the environment
Open PowerShell with administrative privileges and verify you can reach the needed CIM classes on the target host. Ensure you have remote access if you intend to query multiple machines.
Tip: Use Get-Module to confirm CIM/Cmdlets availability. - 2
Query BIOS and motherboard
Run the basic queries to pull BIOS and BaseBoard SerialNumber values. Validate that you get non-empty results and note any missing data.
Tip: If SerialNumber is blank, check vendor policy for your device. - 3
Query drive/physical media
Run the disk and physical media queries. Store outputs in a structured object for later export.
Tip: Not all devices expose all media serials. - 4
Normalize and combine results
Apply trimming, uppercasing, and de-duplication. Merge BIOS, board, and disk data into a single list.
Tip: Avoid hard-coding strings; use pipeline-safe operations. - 5
Export and verify
Export the final dataset to CSV/JSON and run a quick validation against your asset registry.
Tip: Include a source field for provenance. - 6
Automate and reuse
Wrap the logic in a function or module for reuse across machines or workflows.
Tip: Document the function so others can reuse it easily.
Prerequisites
Required
- Required
- Administrative permissions on the target computerRequired
- Basic PowerShell knowledge (pipelines, objects)Required
- Access to CIM/WMI namespaces (e.g., Win32_BIOS, Win32_BaseBoard)Required
Optional
- Optional: PowerShell Remoting configured for remote retrievalOptional
Commands
| Action | Command |
|---|---|
| Get BIOS serial numberPowerShell 3+. CIM cmdlets | Get-CimInstance -ClassName Win32_BIOS | Select-Object SerialNumber |
| Get BaseBoard/Motherboard serialCIM | Get-CimInstance -ClassName Win32_BaseBoard | Select-Object SerialNumber |
| Get DiskDrive serialsHardware-dependent | Get-CimInstance -ClassName Win32_DiskDrive | Select-Object Model, SerialNumber |
| Get Physical Media serialsOptional source | Get-CimInstance -ClassName Win32_PhysicalMedia | Select-Object SerialNumber |
| Export to CSVAfter collecting data | $results | Export-Csv -Path 'C:\serials.csv' -NoTypeInformation |
| Use reusable functionReusable for automation | Get-HwSerials -IncludeDisk |
Frequently Asked Questions
Which PowerShell classes fetch hardware serial numbers?
Key classes include Win32_BIOS for BIOS serials, Win32_BaseBoard for motherboard serials, Win32_DiskDrive for drive serials, and Win32_PhysicalMedia for miscellaneous media. These expose the SerialNumber property on many devices. Some vendors may not populate all fields, so use multiple sources.
You pull serials from BIOS, baseboard, drives, and media using standard CIM classes.
Why would a SerialNumber be blank on a device?
Serial numbers may be hidden by manufacturers for security or privacy, or not exposed by firmware. Some devices use non-standard fields or require vendor-specific tools. Always account for blanks in your reports and document the data provenance.
Sometimes serials are hidden by the device; plan for missing data.
Can I retrieve serial numbers remotely?
Yes. Use PowerShell Remoting or CIM sessions to query remote machines. Ensure proper authentication, firewall rules, and least-privilege access. Start with a lab test before rolling out to production endpoints.
You can pull serials from other machines over the network, with proper permissions.
Is PowerShell sufficient for all devices?
PowerShell works on Windows devices where CIM/WMI namespaces are accessible. Some non-Windows or highly locked devices may require vendor tools or alternative scripting interfaces. Always verify coverage across your estate.
PowerShell covers most Windows devices, but not every device may expose serial data.
How should I export and verify serial data?
Export to CSV/JSON for auditing, then cross-check against your asset registry or inventory system. Include metadata like source class and timestamps to aid verification.
Export your results and double-check against your asset list.
How can I reuse the code for multiple machines?
Encapsulate the logic in a function or module, and parameterize inputs (e.g., IncludeDisk). This enables scalable retrieval across many endpoints with consistent output.
Package the logic so you can run it on many machines easily.
Key Takeaways
- Use CIM classes (Win32_BIOS, Win32_BaseBoard) to fetch primary hardware serials
- Query storage devices with Win32_DiskDrive and Win32_PhysicalMedia where available
- Normalize and export data for audits and inventories
- Create reusable functions to scale across hosts
- Be aware of vendor policies that may hide serial data