How to identify actual used display with Powershell

Niesel, Linus 0 Reputation points


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

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

1 answer

Sort by: Most helpful
  1. Limitless Technology 25,816 Reputation points
    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 {
            $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
    If the reply was helpful, please don’t forget to upvote or accept as answer.
    Best regards.