VirtualDesktop is a Powershell module that provides commandlets to manage virtual desktops of Windows 10 and Windows 11.
Now with support for Windows 11 including Insider up to 24H2
Now with support for Windows Server 2022
Now with support for Powershell Core (pin application commandlets still not work here)
Now with support for Windows Terminal
and other commandlets
By Markus Scholtes, 2024
# Create a new virtual desktop and switch to it
New-Desktop | Switch-Desktop
# Create a new virtual desktop and name it (only on Win 10 2004 or up)
New-Desktop | Set-DesktopName -Name "The new one"
# Get second virtual desktop (count starts with 0) and remove it
Get-Desktop 1 | Remove-Desktop -Verbose
# Retrieves the count of virtual desktops
Get-DesktopCount
# Show list of virtual desktops
Get-DesktopList
# Move notepad window to current virtual desktop
(ps notepad)[0].MainWindowHandle | Move-Window (Get-CurrentDesktop) | Out-Null
# Move powershell window to last virtual desktop and switch to it
Get-Desktop ((Get-DesktopCount)-1) | Move-Window (Get-ConsoleHandle) | Switch-Desktop
# Retrieve virtual desktop on which notepad runs and switch to it
Get-DesktopFromWindow ((Get-Process "notepad")[0].MainWindowHandle) | Switch-Desktop
# Pin notepad to all desktops
Pin-Window ((Get-Process "notepad")[0].MainWindowHandle)
PS C:\> Install-Module VirtualDesktop
or download from here: https://www.powershellgallery.com/packages/VirtualDesktop/.
Also look for the script based version here Powershell commands to manage virtual desktops of Windows 10.
Also look for the C# partner tool here VirtualDesktop.
In most commands you can use a desktop object, the desktop number or a part of the desktop name as parameter desktop, see online help for more information.
Get count of virtual desktops
Show list of virtual desktops
Create virtual desktop. Returns desktop object.
Switch to virtual desktop. Parameter is number of desktop (starting with 0 to count-1) or desktop object.
Remove virtual desktop. Parameter is number of desktop (starting with 0 to count-1) or desktop object. Windows on the desktop to be removed are moved to the virtual desktop to the left except for desktop 0 where the second desktop is used instead. If the current desktop is removed, this fallback desktop is activated too. If no parameter is supplied, the last desktop is removed.
Remove all virtual desktops but visible.
Get current virtual desktop as desktop object.
Get virtual desktop with index number (0 to count-1). Returns desktop object.
Get index number (0 to count-1) of virtual desktop. Returns integer or -1 if not found.
Get name of virtual desktop. Returns string.
Set name of virtual desktop to name. Works only with Windows 10 2004 or up.
Set wallpaper of virtual desktop to path. Works only with Windows 11.
Set wallpaper of all virtual desktops to path. Works only with Windows 11.
Get virtual desktop of window (whose window handle is passed). Returns desktop object.
Checks whether a desktop is the currently displayed virtual desktop. Returns boolean.
Get the desktop object on the "left" side. If there is no desktop on the "left" side $NULL is returned. Returns desktop "left" to current desktop if parameter desktop is omitted.
Get the desktop object on the "right" side.If there is no desktop on the "right" side $NULL is returned. Returns desktop "right" to current desktop if parameter desktop is omitted.
Move current desktop to other virtual desktop. Works only with Windows 11.
Move window whose handle is passed to virtual desktop. The parameter values are auto detected and can change places. The desktop object is handed to the output pipeline for further use. If parameter desktop is omitted, the current desktop is used.
Move active window to virtual desktop. The desktop object is handed to the output pipeline for further use. If parameter desktop is omitted, the current desktop is used.
Check if window whose handle is passed is displayed on virtual desktop. Returns boolean. The parameter values are auto detected and can change places. If parameter desktop is not supplied, the current desktop is used.
Pin window whose window handle is given to all desktops.
Unpin window whose window handle is given to all desktops.
Checks whether a window whose window handle is given is pinned to all desktops. Returns boolean.
Pin application whose window handle is given to all desktops.
Unpin application whose window handle is given to all desktops.
Checks whether an application whose window handle is given is pinned to all desktops. Returns boolean.
Get window handle of powershell console in a safe way (means: if powershell is started in a cmd window, the cmd window handle is returned).
Get window handle of foreground window (the foreground window is always on the current virtual desktop).
Find first window handle to title text or retrieve list of windows with title (when called with * as parameter)