Windows – How to open a program directly to a specific virtual desktop with powershell

powershellvirtual-desktopwindows 10

Here is my situation. I am setting up a monitor screen. Because of the compatibility with different web pages needed to be viewed running a tab switcher in Firefox or Chrome is not working well for all websites. I am now trying to create a virtual desktop switcher that I can open a new process window (browser specific to the website displayed) in different virtual desktops on Windows 10. I found a powershell command set to create the virtual desktops and think I have an infinite loop setup for the switching between the desktops while waiting a specified time between them.

The only thing I am having trouble with is how to open the process in the specific desktop. I didn't want to try to move the process because I may need to open more than one FireFox browser, for instance, and figured it would just pull all the FireFox processes to the same desktop which defeats the purpose.

Link to VirtualDesktop.ps1: https://gallery.technet.microsoft.com/scriptcenter/Powershell-commands-to-d0e79cc5

script as I have it so far:

# Change to VirtualDesktop powershell folder
cd C:\Users\monitor1\Downloads\VirtualDesktop

# Load commands (assumes VirtualDesktop.ps1 is in the current path) 
. .\VirtualDesktop.ps1

# Create a new virtual desktop and switch to it 
New-Desktop | Switch-Desktop

$path = "C:\Program Files\Mozilla Firefox\firefox.exe" 
Start-Process $path -ArgumentList 'https://system.url.com'

# Create a new virtual desktop
New-Desktop | Switch-Desktop

$path = "C:\Program Files\Google\Chrome\Application\chrome.exe"
Start-Process $path -ArgumentList 'http://solarwinds.url.com'

#switch between desktops with a 30 second pause
$VD = 1
while ($VD = 1) {
    $DesktopList = @(1..2)
    foreach ($DesktopNum in $DesktopList) {
        Switch-Desktop -Desktop $DesktopNum
        Start-Sleep -s 30
    }
}

Best Answer

This sounds like a job for psexec

PSExec \COMPUTER_IP_ADDRESS -u UsernameWithAccessToSystem -p Password %Command to run here%