我想我有 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
我已经将路径问题作为错误消息的一部分进行了测试。有任何想法吗 ?
谢谢,菲利普