Wednesday, 17 February 2016

Get Serial Number of a Remote Computer with PowerShell

The serial number can be useful to identify computer hardware for inventory purpose, which is often written on a small sticker in back side of the device. We can also get this serial number from the BIOS configuration. We can retrieve it using the Windows Management Instrumentation (WMI) class Win32_Bios.

The following command get a serial number of the current computer:
Get-WMIObject Win32_Bios | Select-Object SerialNumber

Get Serial Number of a Remote Computer:

You can pass the remote computer name with the paramater -ComputerName and get serial number of remote machine.
Get-WMIObject Win32_Bios -ComputerName 'remote-svr1' | Select-Object SerialNumber

Get Serial Number for a list of Remote Computers using PowerShell:

Use the below powershell script to find serial number for multiple remote computers. First create the text file computers.txt which includes one computer name in each line. You will get the machine name and serial number in the csv file SerialNumbers.csv.
Get-Content C:\computers.txt  | ForEach-Object{
$ser_number = (Get-WMIObject Win32_Bios -ComputerName $_ ).SerialNumber
if(!$ser_number){
$ser_number ="The server is unavailable"
}
New-Object -TypeName PSObject -Property @{
      ComputerName = $_
      SerialNumber = $ser_number
}} | Select ComputerName,SerialNumber |
Export-Csv C:\SerialNumbers.csv -NoTypeInformation -Encoding UTF8

Get Serial Number for a list of Remote Computers from CSV:

Use the below powershell script to to find serial number for multiple remote computers from csv file. First create the csv file computers.csv which includes the column ComputerName in the csv file. You will get the ComputerName and SerialNumber list in the csv file SerialNumbers.csv.
Import-Csv C:\computers.csv | ForEach-Object{
$ser_number = (Get-WMIObject Win32_Bios -ComputerName $_.ComputerName).SerialNumber
if(!$ser_number){
$ser_number ="The server is unavailable"
}
New-Object -TypeName PSObject -Property @{
      ComputerName = $_.ComputerName
      SerialNumber = $ser_number
}} | Select ComputerName,SerialNumber |
Export-Csv C:\SerialNumbers.csv -NoTypeInformation -Encoding UTF8

Advertisements
Advertisements

1 comment:

  1. Hello Morgan,
    Thanks for such a valuable blog!
    While testing above script "Get Serial Number of a Remote Computer with PowerShell" I am getting below error "Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:2 char:29
    + $ser_number = (Get-WMIObject <<<< Win32_Bios -ComputerName $_ ).SerialNumber
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand"

    I had tested with single user that means its not related with access/permission issue.
    Could you please assist me here.

    ReplyDelete