I'm looking forward to run special commands on a target machine in my local network (workgroup, no domain join).

The machines have been previously configured with Enable-PSremoting etc.. to tolerate Windows remote management so that we can execute a command on the target machine as follows.

The commands work fine except that if I want to start some special commands like start-process, they are not executed as the local machine.

For example, if I run on my local machine:

> Start-Process -Filepath "cmd.exe"

it starts cmd process. If I do it remotely, like this

Invoke-Command -Computername "my-target-ip" -ScriptBlock {Start-Process -Filepath "cmd.exe"} -Credential get-credential

The cmd window is not executed on the target machine.

This would allow me to install some special packages on my target machines which require some autoit GUI configs and which can not be just made via powershell like pausing updates and setting up standard browser apps via the GUI. Otherwise, some normal configs work fine (firewall settings, writing files, enabling network configs etc.)

Thank you very much.


Invoke-Command is meant for noninteractive commands. IIRC you won't get an interactive prompt using it, and of course, if you want to start a program on the remote computer it should exist there before your start it.

If you want to use an interactive session on the remote computer you should use Enter-PSSession instead:

Enter-PSSession -Computer "remote" -Credential (Get-Credential)

Inside this session you should be able to start a cmd prompt if you really need it.

If you need to run a number of related commands that are not interactive the New-PSSession cmdlet could be of interest, along with Invoke-Command -Session $session.

  • Thanks. And if I generate a cmd file let's say in c:\install.cmd with the Invoke-Command cmdlet and I execute it? – Andy McRae Aug 18 '20 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.