How to Get the Serial Number of a Remote Computer Using PowerShell

PowerShell

Sometimes it can be useful to identify computer hardware for inventory purposes using its serial number, which is often written on a small sticker affixed to the underside of the device. The serial number is also found in the BIOS, and can be retrieved using Windows Management Instrumentation (WMI).

In this edition of Ask the Admin, I’ll show you how to use PowerShell to get the serial number of a local or remote computer from the computer BIOS.

Retrieving the Serial Number from a Local Computer Using PowerShell get Serial Number

The get-ciminstance PowerShell command was introduced in PowerShell 3.0. It allows administrators to run WMI queries on local or remote computers. To retrieve the BIOS serial number of the local computer, we need to access the Win32_BIOS WMI class.

Log on to Windows Server 2012 R2, click the PowerShell icon on the desktop taskbar. In the prompt window, run the following command:

​ get-ciminstance win32_bios

To display only the serial number, type:

​ get-ciminstance win32_bios | format-list serialnumber

Using PowerShell and WMI to get the serial number of a computer
Using PowerShell and WMI to get the serial number of a computer. (Source: Russell Smith)

Retrieving the Serial Number from a Remote Computer

The get-ciminstance cmdlet creates a temporary session to remote computers using the WSMAN protocol over HTTP. Windows Remote Management (WINRM) is enabled by default in Windows Server 2012 R2. If it is not enabled on the remote computer you want to query, or the default WINRM listener has been deleted, run winrm qc at an elevated command prompt on the remote device to add the default listener.

​ get-ciminstance -classname win32_bios -computername contososrv1 | format-list serialnumber

After –computername in the example above, replace contososrv1 with the name of the remote server you want to query.

Using PowerShell get Serial Number on Windows Server 2003 and XP

The above commands should work if the remote computer is Windows 2008, Vista or later. To query Windows Server 2003 or XP, we need to configure a session that uses the DCOM protocol instead of WSMAN.

Run the following three commands in a PowerShell prompt to retrieve the serial number from a remote Windows Server 2003 computer, replacing contososrv1 with the name of the remote server:

​$sessionoption = new-cimsessionoption -protocol dcom
$cimsession = new-cimsession -sessionoption $sessionoption -computername contososrv1
get-ciminstance win32_bios -cimsession $cimsession

FAQs

What is the fastest PowerShell command to get the serial numbers for multiple computers in a domain?

To quickly get serial numbers for multiple computers, use the PowerShell command: “Get-ADComputer -Filter * | ForEach-Object {Get-CimInstance -ComputerName $_.Name -ClassName Win32_BIOS | Select-Object PSComputerName, SerialNumber}” This method efficiently retrieves Serial Numbers from all domain-connected devices.

Can I export the PowerShell serial number results to CSV or Excel?

Yes, append the Export-CSV cmdlet to your PowerShell get serial number command: “Get-CimInstance Win32_BIOS | Select SerialNumber | Export-CSV C:\SerialNumbers.csv”. This creates a formatted spreadsheet with all retrieved Serial Numbers.

How can I use PowerShell to get serial number information from offline computers?

PowerShell can retrieve serial number data from offline computers by accessing cached WMI information stored in the registry. Use “Get-ItemProperty HKLM:\HARDWARE\DESCRIPTION\System\BIOS” to access this information.

Is it possible to schedule automated PowerShell serial number collection?

Yes, create a PowerShell script for serial number collection and use Task Scheduler to automate it. Set up recurring tasks that run your PowerShell get serial number script at specified intervals and store results in a designated location.

What permissions are required to use PowerShell get serial number commands remotely?

To use PowerShell get serial number commands remotely, you need local administrator rights on target machines, WinRM enabled, and proper firewall configurations. Domain Admin privileges might be required for domain-wide serial number collection.