powershellremote-servernon-interactive

Noninteractive Remote Commands with Powershell


I am developing a script which uses ssh to connect to a windows host, run a powershell command, and parse the output. While I can connect to the host and run the command, powershell will not exit and return control back to the local script until I press the enter key.

At the moment, the specific command being run is ssh HOSTNAME 'echo $(hostname)' and the ssh server is configured to pass remote execution requests to powershell -noninteractive -command CMD, where HOSTNAME is the name of the windows host and CMD is the remote command to be run (in this case echo $(hostname)).

The end goal is to have the script which is calling remote powershell commands to run completely noninteractively, but this is currently impossible as the powershell command will not run noninteractively.

How do I get powershell to run remote commands noninteractively?


Solution

  • I've resolved the issue. While I haven't determined what was causing the issue, I can at least overcome the issue at hand by redirecting stdin to /dev/null on the side that initiates the ssh connection.

    $ ssh HOSTNAME "CMD" </dev/null
    

    This solution doesn't involve powershell at all, but rather treats the symptoms from the other side of the connection.