简体   繁体   中英

How do I execute a remote command in Powershell interactively?

I'd like to run a command on a remote machine interactively using PowerShell, similar to how when passing an argument to ssh it runs just that program. For instance, this would open a connection, execute program and then return back to your normal shell.

$ ssh username@somehost program

I know I can use Enter-PSSession to get into the session, but I'd have to manually enter the program name. If I use Invoke-Command with -Session , I can get it to execute the program I want, but then that program crashes if it's expecting user input.

It doesn't look good. Looking for a way to run it off a fileshare might be easier.

invoke-command comp001 { python -c "raw_input('type something')" }

Traceback (most recent call last):
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : arc001

  File "<string>", line 1, in <module>
EOFError: EOF when reading a line
type something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM