Displaying monitor model and input it is using

Evening all

After hours and hours of searching on how to display monitor model i found what i needed. I’ve adapted it for my need and was wondering if it would be possible to add 2 classes together from WmiMonitorBasicDisplayParams & WmiMonitorID.

Basically i want an output that gives me the Model & Input it’s using. WmiMonitorBasicDisplayParams-VideoInputType will give me an output 1 = Digital & 0 = Analog and the rest of the script is below… Please help

Function MonitorInfo {

$test = "IP or PC name"
        $ActiveMonitors = Get-WmiObject -Namespace "ROOT\WMI" -ComputerName $test -Query "SELECT * FROM WmiMonitorID WHERE Active='True'"
        $monitorInfo = @()

        foreach ($monitor in $ActiveMonitors) {
            $mon = @{}
            $name = $null

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

            $mon = $name

            $monitorInfo += $mon
        }
        $monitorInfo
    }

$Moninfo = MonitorInfo

# Write out to file(s)

$Moninfo

This is the line for the Inout type

Get-WmiObject -Namespace ‘root\wmi’ -ComputerName $test -class WmiMonitorBasicDisplayParams | select VideoInputType

Cheers

Try to create a custom object, and combine the results in there. A example:

[PSCustomObject]@{
    MonitorName = $monitor.UserFriendlyName
    MonitorMode = $monitor.Model
}

More information here: https://powershell.org/kb/new-object-psobject-vs-pscustomobject/

This should do what you want and can serve as a template for adding other properties or combining other classes

function Get-MonitorInfo {
    [CmdletBinding()]
    param(
        $computername = $env:COMPUTERNAME
    )

    $monitors =  Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorId -Filter "Active = '$true'" -ComputerName $computername
    
    foreach ($monitor in $monitors) {
        
        $in = ($monitor.InstanceName).Replace('\', '\\')
        Write-Verbose -Message $in
        $dp = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams -Filter "InstanceName = '$in'" -ComputerName $computername
        
        $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
        }
    }
}

Richard, why do you use New-Object vs. the type accelerator?

Because its a simpler explanation to someone getting started with this. You end up at the same place:

PS> $x = [PSCustomObject]@{
>> Name = 'name'
>> Type = 'type'
>> }
PS> $x

Name Type
---- ----
name type


PS> $x | gm


   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
Name        NoteProperty string Name=name
Type        NoteProperty string Type=type


PS> $y = New-Object -TypeName PSObject -Property @{
>> Name = 'name'
>> Type = 'type'
>> }
PS> $y

Name Type
---- ----
name type


PS> $y | gm


   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
Name        NoteProperty string Name=name
Type        NoteProperty string Type=type

But its more obvious what is happening. Also New-Object works in more versions of PowerShell than [pscustomobject]@{}

Fair enough! Thanks Richard and see you next week at psconf!

Thanks guys it’s all working :slight_smile: