-1

我想我有 90% 的正确率,但似乎少了一小部分......

我从 Windows -> Linux(主机)打开远程会话没有问题,传递命令也没有问题。这工作正常:

$Session = New-PSSession -SSHTransport -HostName 192.168.0.10 -UserName user
Invoke-Command -Session $Session { bash ~/sh/test.sh }

但是当我尝试将我的命令变成一个变量时:

$cmd = "bash ~/sh/test.sh"
Invoke-Command -Session $Session { & "$using:cmd" }

我收到以下错误消息:

The term 'bash ~/sh/test.sh' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo          : ObjectNotFound: (bash ~/sh/test.sh:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName        : 192.168.0.10

我已经将路径问题作为错误消息的一部分进行了测试。有任何想法吗 ?

谢谢,菲利普

4

1 回答 1

0

我的回答是暂时的解决方法。错误可能仍然存在于 Powershell 远程处理中 :-)

1)修改你的test.sh文件,把它变成一个Powershell脚本:test.ps1(希望你没有复杂的脚本)

2)然后它工作得很好:

$cmd = "~/sh/test.ps1"
Invoke-Command -Session $Session { & "$using:cmd" }

其他想法更受欢迎!

于 2019-02-25T12:17:00.533 回答