Inventory script – monitor serial number

By | 9th October 2022

A small script written in PowerShell helps to collect all data about connected devices [monitors] from computers.
The script collects the following data:

  • make, model and serial number of the monitor [VGA and/or HDMI]
  • user name
  • computer name

All data is saved to a TXT file [can be easily changed to CSV]

$UserName = $env:UserName;
$computername = $env:COMPUTERNAME;
$Year = Get-WmiObject win32_bios | Select Version, SerialNumber
$WinVer = Get-ComputerInfo -Property "OsVersion"
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi
$File = "./Monitors/monitors.txt"


function Decode {
    If ($args[0] -is [System.Array]) {
        [System.Text.Encoding]::ASCII.GetString($args[0])
    }
    Else {
        "Not Found"
    }
}
   
echo "Manufacturer", "Name, Serial"
   
ForEach ($Monitor in $Monitors) {  
    $Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
    $Name = Decode $Monitor.UserFriendlyName -notmatch 0
    $Serial = Decode $Monitor.SerialNumberID -notmatch 0
   
    echo "$UserName, $Computername, $CompSerial, $WinVer, $Year, $Manufacturer, $Name, $Serial" >> $File
}