通过Cygwin / OpenSHH尝试从Ubuntu主机到Windows客户端的以下命令。
ssh USER@HOSTNAME powershell -Command "& {Get-Host}"
输出:
Cannot process the command because of a missing parameter. A command must follow -Command.
然而,当我在Windows客户端中尝试使用相同的命令而不是cygwin时,我得到了正确的输出。
$ powershell -Command "& {Get-Host}"
Welcome to Powershell augmented with NaviNet tools.
Bootstrapped ScmToolsProjectConfiguration.
Name : ConsoleHost
Version : 2.0
InstanceId : 0b2e578e-50b9-42ab-a07c-0c4ef762ba0c
UI : System.Management.Automation.Internal.Host.InternalHostUser
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
答案 0 :(得分:1)
试图逃避“,所以它看起来像:
ssh USER@HOSTNAME powershell -Command \"& {Get-Host}\"
如果这不起作用,请尝试逃避{,}和/或&太。我认为这是一个逃避问题;)
编辑:
甚至尝试用\\\“来逃避它,这会导致转义”和\。 (不知道powershell想要命令,不熟悉它)
答案 1 :(得分:0)
ssh USER@HOSTNAME powershell -Command "& {Get-Host}"
运行此命令时,本地系统上的ssh程序将获取参数:
在执行ssh
之前,本地shell会删除最后一个参数周围的双引号。 ssh
然后将构成远程命令的三个参数连接成一个字符串:
它将此字符串发送到要执行的远程系统。远程系统不会按照您希望的方式解释此字符串。
您需要以这样的方式发出命令:引号包含在发送到远程系统的命令版本中。这应该这样做:
ssh USER@HOSTNAME 'powershell -Command "& {Get-Host}"'