hello guys ,

im trying to export the computers serialnumbers + screens serialnumbers , for that i have this powershell script

$ComputerName = 'computers'
$bios = Get-WmiObject win32_bios -ComputerName $ComputerName | select pscomputername,serialnumber,name,serial
$mon = Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Name = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""
    }
} 

Write-Output $bios,$mon

in the output in the column " name " im getting both names of pc and screen

PSComputerName serialnumber name                serial    
-------------- ------------ ----                ------    
computer       XXXXXXXXXX   Default System BIOS           
                            HP P201             XXXXXXXXX

… i would like to get only the name of the screen … how can i do that ?

thank you

6 Spice ups

try:

$bios = Get-WmiObject win32_bios -ComputerName $ComputerName | select pscomputername,serialnumber,monname,serial
$mon = Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        monname = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""
    }
} 

Write-Output $bios,$mon
1 Spice up

it worked … but still im getting the screen name on another row … i want them on the same row if possible because i want to export them to a csv

can it be done ?

Ah I see how you mean it, look at this:

$ComputerName = 'computername'
$bios = Get-WmiObject win32_bios -ComputerName $ComputerName | select pscomputername,serialnumber,name,monname,serial
$mon = Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        monname = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""
    }
} 

Write-Output $bios,$mon|ft
2 Spice ups

Think they meant like this:

$results = @()

$bios = Get-WmiObject win32_bios -ComputerName $ComputerName | select pscomputername,serialnumber
Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	$mon = New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        monname = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""
    }
    $results += [pscustomobject]@{
        PCName = $bios.PSComputerName
        PCSerialNo = $bios.serialnumber
        MonName = $mon.monname
        MonSerialNo = $mon.Serial
        MonManufacturer = $mon.Manufacturer
    }
}

$results | Export-Csv -Path "C:\Blah.csv" -NoTypeInformation
3 Spice ups
Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	$mon = New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        monname = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""

can someone explain this to me ? how is this working ?

because when i run

Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName

i get some weird numbers like

ManufacturerName       : {12, 34, 45, 0...}
ProductCodeID          : {59, 53, 56, 49...}
SerialNumberID         : {55, 66, 77, 88...}
UserFriendlyName       : {33, 22, 11, 99...}
UserFriendlyNameLength : 13

thank you

Hi,

these information were stored as uint16 Arrays, check WmiMonitorID class - Win32 apps | Microsoft Learn

A source of this

Foreach {[char]$_} ...

is also in this article.

The char part casts the uint16 to “normal” ASCII and join joins them together

1 Spice up

hello guys …

i know this is a solved question … but i’m getting an error in the exported csv

PCName PCSerialNo
System.Object System.Object
System.Object System.Object

this happens when i use it like this

$computername = Get-Content C:\Users\user\Desktop\test.txt
$results = @()

$bios = Get-WmiObject win32_bios -ComputerName $ComputerName | select pscomputername,serialnumber
Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach {
	$mon = New-Object -TypeName psobject -Property @{
        Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join ""
        monname = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join ""
        Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join ""
    }
    $results += [pscustomobject]@{
        PCName = $bios.PSComputerName
        PCSerialNo = $bios.serialnumber
        MonName = $mon.monname
        MonSerialNo = $mon.Serial
        MonManufacturer = $mon.Manufacturer
    }
}

$results | Export-Csv -Path "C:\Blah.csv" -NoTypeInformation

note that when i use it on a single computer … it works fine … but when i put multiple computers in the text file … it shows this error … any help please

Well, yes. It would. It’s not an error, it is the way the code is written.

The first line gets the bios info for all the computers then the second line get’s the monitor infor for all the computers.

When you combine them then all the bios data is being stuffed into each individual piece of monitor data.

You’d probably have to redo this logic with a foreach loop rather than trying to use 2 pipelines.

1 Spice up

well … can u help me with it ? i honestly dont know how to do that

Well your basic structure would look something like:

$ComputerName = # 1 or more computer names go here...
$results = foreach($sysName in $ComputerName)
{
    $bios = Get-WmiObject win32_bios -ComputerName $sysName | 

    $mon = Get-WmiObject -Namespace root\wmi -ClassName wmimonitorid -ComputerName $sysName | 

    [PSCustomObject]@{
        PCName = $bios.PSComputerName
        PCSerialNo = $bios.serialnumber
        MonName = $mon.monname
        MonSerialNo = $mon.Serial
        MonManufacturer = $mon.Manufacturer
    }
}

$results | Export-Csv -Path "C:\Blah.csv" -NoTypeInformation

This is obviously missing some code, I’m providing the outline here.