How to identify actual used display with Powershell

Niesel, Linus 0 Reputation points
2023-05-24T06:12:14.9033333+00:00

Hi,

I have a PowerShell script with a GUI in a multi monitor environment. When moving the GUI Window from one screen to another, is there any possibility to check on which screen the window is (in order to reset the resolution of the GUI Window according to screen resolution/size). I have identified all screens with their resolution, but I cannot identify on which screen the window is programmatically...

Cheers, Linus

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,045 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 43,931 Reputation points
    2023-05-24T10:44:03.0166667+00:00
    Hello Linus,
    
    Thank you for your question and for reaching out with your question today.
    
    I have used the following code in the past to identify the monitors within my multi monitor setup:
    
    function GetMonitorSerial () {
            $Monitor =(Get-WmiObject -NameSpace root\wmi -Class wmiMonitorID -EA 0 | ForEach-Object {
                $([System.Text.Encoding]::Ascii.GetString($($_.SerialNumberID)))
            })
    
            $MON0 = $Monitor[0]
            $MON1 = $Monitor[1]
        $MON2 = $Monitor[2]
        $MON3 = $Monitor[3]
            Write-Host "Monitor #0: " $MON0
            Write-Host "Monitor #1: " $MON1
        Write-Host "Monitor #2: " $MON2
        Write-Host "Monitor #3: " $MON3
        }
    
        GetMonitorSerial
    
    If the reply was helpful, please don’t forget to upvote or accept as answer.
    
    Best regards.