Running this command
$processesToSpawn = 3
for($i= 1; $i -le $processesToSpawn; $i++){
psexec \\computername -i 2 -u "username" -p "password" "c:\myapp.exe"
}
Produces the following error
psexec :
At C:\mypsScript.ps1:75 char:13
+ psexec \\computername -i 2 -u "username" -p " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
It executes and runs the first iteration of the loop fine, and opens the program that i want in the RDP session, but fails immediately after the first iteration.
Edit: The is only happens in the IDE, running the script from a PS command line runs fine. So consider this question solved.
Additionally, i had to add the -d switch to the PSExec command (Don't wait for process to terminate (non-interactive).)