gpt4 book ai didi

python - 通过 SSH 执行 Powershell 命令

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:43 28 4
gpt4 key购买 nike

尝试通过 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

最佳答案

尝试转义",所以它看起来像:

ssh USER@HOSTNAME powershell -Command \"& {Get-Host}\"

如果这不起作用,请尝试转义 {,} 和/或 &。我认为这是一个逃避问题;)

编辑:

或者甚至尝试用\\\"转义它,这会导致转义的 "和\。 (不知道powershell是怎么要命令的,不熟悉)

关于python - 通过 SSH 执行 Powershell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6423879/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com