r/PowerShell 18d ago

Question Reliably switching primary display at boot via script — looking for the right approach

Setup: Windows 11 | RTX 5080 | Three displays: physical monitor (ID: AUS274D), a case-mounted display (ID: RTK409A), and a Virtual Display Driver (ID: MTT1337)

Goal: A PowerShell script triggered at logon via Task Scheduler that: 1. Detects whether the physical monitor is connected at boot 2. If yes → set it as primary, virtual display disabled 3. If no → set virtual display as primary, all physical displays disabled

Using the monitor cable as a boot-time toggle — no menus, no manual steps.

Current approach: Detecting monitor presence via MultiMonitorTool's CSV export (Short Monitor ID), then switching primary with /SetPrimary and /enable / /disable.

Questions: - Is Short Monitor ID detection via MultiMonitorTool reliable before GPU drivers fully initialize at boot? - Is there a more reliable detection method — WMI, EDID query, registry? - Any known timing issues with display enumeration on NVIDIA systems at logon?

Open to alternative tools if MultiMonitorTool isn't the right fit here.

4 Upvotes

11 comments sorted by

3

u/arslearsle 18d ago

Check out
Get-CimInstance win32_pnpentity | where{$_.pnpclass -eq 'monitor'}
Good luck!

3

u/purplemonkeymad 18d ago

I don't know about the issue, but in the past we have used dummy hdmi connectors that just present as a 1080p monitor to solve any virtual monitor issues. That way it's always a "real" display to windows.

1

u/Dazzling-Neat-6278 17d ago

I've already setup a VDD which is working phenomenally.

1

u/MartinGC94 18d ago

If you are physically changing the setup then Windows should recognize that and restore whatever configuration that physical configuration had the last time it was used so you shouldn't even have to script this in the first place.

I don't know anything about MultiMonitorTool so I can't comment on that, but I have made my own PowerShell module that should be able to handle this: DisplayConfig. You can use $DisplayInfo = Get-DisplayInfo to get info about your current setup (The positions of each individual display, EDID info like the monitor serial number and whether or not they are active or primary).
When you have that data you just need to define your logic and run Set-DisplayPrimary accordingly. Simple demo script:

$DisplayInfo = Get-DisplayInfo
$InternalDisplay = $DisplayInfo | where {$_.EdidData.SerialNumber -eq '123'}
$OtherDisplay = $DisplayInfo | where {$_.EdidData.SerialNumber -eq 'ABC'}

if ($InternalDisplay.Active)
{
    Set-DisplayPrimary -DisplayId $InternalDisplay.DisplayId
}
elseif ($OtherDisplay.Active)
{
    Set-DisplayPrimary -DisplayId $OtherDisplay.DisplayId
}

1

u/Dazzling-Neat-6278 18d ago

This looks really clean — thanks for sharing. Quick question before I commit to it: can the module also enable or activate a display that's currently inactive/disabled in Windows, not just switch primary among already-active displays? Specifically I need to enable a Virtual Display Driver (VDD) that may be in a disconnected state at boot. Is there a Set-DisplayActive or similar command in the module for that? Additionally, can I use it to extend my other monitors to for example, case-mounted display?

1

u/MartinGC94 18d ago

Yes, the module also includes Enable/Disable-Display commands among others. Basically anything that you can do in the Display section of the settings app should be supported.

1

u/Dazzling-Neat-6278 18d ago

Awesome! Share me the link to Github repo or some commands. I need to first do some experiment using it to verify its credibility.

2

u/BlackV 17d ago
Find-command -name  Get-DisplayInfo

1

u/Dazzling-Neat-6278 17d ago

BTW, can I make DisplayConfig API calls work correctly from Session 0 context before any user session exists.

1

u/BlackV 17d ago

Questions: - Is Short Monitor ID detection via MultiMonitorTool reliable before GPU drivers fully initialize at boot?

You can't run a script before windows is fully booted, PowerShell is not there, anything you're running is post boot

So a scheduled task is your best bet

Do you have working code already?

1

u/Dazzling-Neat-6278 17d ago edited 17d ago

Yes, I have a working PowerShell proof of concept using Win32_PnPEntity for monitor detection and MultiMonitorTool for switching. The limitation I hit is that Task Scheduler runs post-login, so I'm now exploring a Session 0 Windows Service to enforce the display state before winlogon renders the login screen. The question is whether DisplayConfig API calls work correctly from Session 0 context before any user session exists.

EDITED: I found out that Task Scheduler can run pre-login. I might have tried to over-engineer it, I guess 🤷 I'm exploring this approach now. Let's see where it goes.