我想我的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
我已经测试了路径问题作为错误消息的一部分。有什么想法吗?
谢谢菲利普
我的答案暂时是一个工作。错误可能保留在powershell远程中: - )
1)调整您的test.sh文件以将其转换为PowerShell脚本:test.ps1(希望您没有复杂的脚本)
2)然后效果很好:
$cmd = "~/sh/test.ps1"
Invoke-Command -Session $Session { & "$using:cmd" }
其他想法非常欢迎!