Get serial# from WMIMonitorID - wrong format, what am I missing?

Here my short script - PC info comes through but monitor serial number doesn’t look right.

Help.

Computer Info for current PC

cls

$CS = Get-WmiObject -Class Win32_ComputerSystem
$Monitor = Get-CimInstance -Namespace root\wmi -ClassName wmimonitorid

New-Object -Typename psobject -Property @{
Model = $CS.Model
PCName = $CS.Name
“Monitor Serial Number” = $Monitor.$_.SerialNumberID
}

The data returned in SerialNumberID is a byte array. You can convert it like this.

$CS = Get-WmiObject -Class Win32_ComputerSystem
$Monitor = Get-CimInstance -Namespace root\wmi -ClassName wmimonitorid

[PSCustomObject]@{
    Model = $CS.Model
    PCName = $CS.Name
    “Monitor Serial Number” = [System.Text.Encoding]::ASCII.GetString($Monitor.SerialNumberID)
}

However, if you have more than one monitor you will end up with all serial numbers.

Here’s one way to account for multiple monitors.

# Computer Info for current PC
cls

$CS = Get-WmiObject -Class Win32_ComputerSystem
$Monitor = Get-CimInstance -Namespace root\wmi -ClassName wmimonitorid

$script = {[System.Text.Encoding]::ASCII.GetString($args[0])}

$PC = [ordered]@{
    PCName = $CS.Name
    Model  = $CS.Model
}

1..$Monitor.count | foreach {
    $pc += @{
        "Monitor$_ Name"   = . $script ($Monitor[$_ - 1]).userfriendlyname
        "Monitor$_ Serial" = . $script ($Monitor[$_ - 1]).SerialNumberID
    }
}
[PSCustomObject]$PC

Output on my PC

PCName          : DESKTOP-NEKK74J
Model           : 410599U
Monitor1 Name   : DELL 2408WFP 
Monitor1 Serial : G283H97DEF45    
Monitor2 Name   : DELL U2412M  
Monitor2 Serial : YMYH142EABC1  

Thank you, Doug. This is what I was looking for, [System.Text.Encoding]::ASCII.GetString.

Like you comments suggested, I will have to use both script versions because we have mixed setups: Single and dual monitors.

All the best, Gideon.