Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2012 02:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save beckus/4248027 to your computer and use it in GitHub Desktop.
Starts a VirtualBox Virtual Machine with the maximum possible number of virtual monitors.
# Starts the specified VirtualBox virtual machine with the maximum number
# of virtual monitors (i.e. with the number of virtual monitors matching the
# number of physical monitors attached to the PC).
# Set these variables as appropriate for your environment.
$virtualboxBinFolder = "C:\Program Files\Oracle\VirtualBox"
$VMName = "MyVirtualMachine"
# Returns the physical monitor count for this PC.
Function GetMonitorCount
# See
Add-Type -AssemblyName System.Windows.Forms
$allScreens = [System.Windows.Forms.Screen]::AllScreens
return $allScreens.Length
# Sets the virtual monitor count on the specified VirtualBox virtual machine,
# and then starts the machine.
# Assumes the $virtualboxBinFolder global variable points to VirtualBox's bin folder.
Function StartVMWithMonitorCount ($VMName, $monitorCount)
& "$virtualboxBinFolder\VBoxManage" modifyvm $VMName --monitorcount $monitorCount
& "$virtualboxBinFolder\VBoxManage" startvm $VMName
StartVMWithMonitorCount $VMName (GetMonitorCount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment