VirtualBox – PowerShell Script to Start a Virtual Machine with the Maximum Number of Monitors

With the help of a Plugable UGA-2K-A, I sometimes attach an extra monitor to my PC.  I have a VirtualBox virtual machine that I like to run across all of my physical monitors, and I used to manually change the virtual machine’s Monitor Count when connecting or disconnecting the extra monitor.  I now have a PowerShell script which automatically detects the number of monitors connected to my PC, sets the Monitor Count of the virtual machine, and then starts the machine.  I am using the script on a Windows 8 host. I posted the script in this GitHub Gist.

Update: I found this blog entry, which has a similar script (although some of the mechanics are different).