I'm trying to get the hang of using Invoke-Command in PowerShell. My setup seems fine since I can successfully enter PSSessions and work on other machines. I'm attempting to run a basic script that launches the calculator app, just to familiarize myself with how it works. The command I'm using is:
Invoke-Command -FilePath C:scriptscalc-script.ps1 -ComputerName [target-computer-here].
Although the command executes without any errors, the calculator doesn't launch on the target machine. The content of calc-script.ps1 is just a simple line: Start-Process "calc" (I've also experimented with different paths like calc.exe and c:windowssystem32calc.exe). I feel like I'm missing something key here.
3 Answers
When you run a command like that, it doesn't execute in the user session that is currently logged in. Instead, PowerShell creates a new logon session for your command, which means the calculator probably just starts and then exits because it can't find a UI to attach to. A better test would be to write to a log file: `Set-Content ~test.log -Value "remote command ran"`.
It seems like the calculator isn't showing up because it's being launched in a hidden session. You might actually see it in the task scheduler, but since it’s a GUI application, you won't be able to interact with it. Generally, running GUI apps through remote sessions isn't the best practice; consider performing commands that don’t require a user interface, like using `Get-Disk` instead.
Just a heads up, directly interacting with remote user sessions via scripts isn't really feasible for security reasons. If you want a script to run for a remote user, it’s better to save it somewhere they can access, like their startup folder. This way, it can execute automatically when they log in.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically