Batch-Getting BIOS Serial Numbers

Our lab maps hosts to KVM Ports based on, not hostname, not IP address, but the BIOS Serial Number.

Like the last post, this is probably overkill on (Get-WmiObject -ComputerName $ComputerName Win32_BIOS).SerialNumber, but it's probably useful.  Possibly.

 

function Get-SerialNumber {
     param (
         [Parameter( 
             Position = 0,  
             ValueFromPipeline = $true, 
             ValueFromPipelineByPropertyName = $true 
         )][string[]]$ComputerName = @()
     );
    
     process {
         foreach ($computer in $ComputerName) {
             try {
                 $wmi = Get-WmiObject -ComputerName $computer Win32_BIOS;
             }
             catch {
             }
            
             $SerialNumber = $wmi.SerialNumber;
             if (!$SerialNumber) { $SerialNumber = 'ERROR'; }
             1 | Select-Object -Property @{
                 n = 'ComputerName';
                 e = { $computer; }
             }, @{
                 n = 'SerialNumber';
                 e = { $SerialNumber; }
             }
         }
     }
}