header image

Monitor Info

Posted by: | April 12, 2016 Comments Off on Monitor Info |

A question on the forum about combining information from 2 CIM classes produced this:


function Get-MonitorInfo {
        $computername = $env:COMPUTERNAME

    $cs = New-CimSession -ComputerName $computername
    $monitors =  Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorId -Filter "Active = ‘$true’" -CimSession $cs
    foreach ($monitor in $monitors) {
        $in = ($monitor.InstanceName).Replace(‘\’, ‘\\’)
        Write-Verbose -Message $in
        $dp = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams -Filter "InstanceName = ‘$in’" -CimSession $cs
        $name = ”

        foreach ($c in $monitor.UserFriendlyName){
            if ($c -ne ’00’){$name += [char]$c}

        $type = ‘Unknown’
        switch ($dp.VideoInputType){
            0 {$type = ‘Analog’}
            1 {$type = ‘Digital’}
        New-Object -TypeName PSObject -Property @{
            Name = $name
            Type = $type
    Remove-CimSession -CimSession $cs


Create a CIM session to the computer. Get the instances of the WmiMonitorId class. Iterate through them and find the matching WmiMonitorBasicDisplayParams class instance.


The InstanceName of the monitor will look like this:


you need to replace \ by \\ to use the value in a CIM query because \ is treated as the escape character and you have to escape it to use it


Translate the UserFriendly name by converting the byte array to a string and determine the VideoInputType using the switch.


Create an object and output

under: PowerShell and CIM, PowerShell and WMI, PowerShell Basics

Comments are closed.