Why Isn’t My Invoke-Command Script Opening Calculator on Remote Computer?

0
6
Asked By TechnoWizard003 On

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

Answered By ScriptingSage42 On

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"`.

Answered By CodeNinja88 On

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.

Answered By DevGuru202 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.