'Powershell: Get specific firefox window

As part of working with the VirtualDesktop module, I need to get the MainWindowHandle of a particular firefox window in order to put it where I want it. It seems like most firefox processes don't have a MainWindowHandle:

PS> (ps firefox)[0].MainWindowHandle
0
PS> (ps firefox)[2].MainWindowHandle
591744
PS> (ps firefox).Length
19 

What's interesting about the last bit of this is that I have 19 firefox tabs open across all my virtual desktops. Somewhere in an earlier question it mentioned that firefox perhaps uses win32 Windowless Controls, and so wouldn't necessarily have a window handle.

If I run ps firefox |format-table id, name, mainWindowTitle, mainWindowHandle then I can see that, in fact, only the most recently accessed tab has a mainWindowTitle or mainWindowHandle

I know that firefox pulls a little sneaky on us RE processes for performance/stability reasons. Are there any APIs (Moz or MS) that understand how to tear it into digestible bits?

Working code below for additional context:

# Setup windows on first open
Get-Desktop 1 | Switch-Desktop
Start-Process firefox.exe "-new-window open.spotify.com"
Start-Process firefox.exe "-new-window discord.com/channels/@me"
Start-Process -wait firefox.exe "-new-window gmail.com"
Get-Desktop 0 | Switch-Desktop
Start-Process code


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source