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

This entry was posted in PowerShell and CIM, PowerShell and WMI, Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s