简体   繁体   English

Powershell 远程处理 Windows -> Linux:提交参数化脚本

[英]Powershell remoting Windows -> Linux : submit a parametrized script

I guess I have it 90% correct, but a small part seems to be missing...我想我有 90% 正确,但似乎缺少一小部分......

I have no problem opening a remote session from Windows -> Linux (host) No problem passing a command either.我从 Windows 打开远程会话没有问题 -> Linux (host) 传递命令也没有问题。 This works fine:这工作正常:

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

But when I try to turn my command into a variable:但是当我尝试将命令转换为变量时:

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

I get the following error message:我收到以下错误消息:

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

I have tested the path issue as part of the error message.我已将路径问题作为错误消息的一部分进行了测试。 Any ideas ?有任何想法吗 ?

Thanks, Philippe谢谢,菲利普

My answer is a workaroud for the time being.我的回答是暂时的解决方法。 Bugs probably remain in Powershell remoting :-)错误可能仍然存在于 Powershell 远程处理中 :-)

1) Adapt your test.sh file to turn it into a Powershell script: test.ps1 (hope you don't have complex scripts) 1)修改你的test.sh文件,把它变成Powershell脚本:test.ps1(希望你没有复杂的脚本)

2) Then it works just fine: 2)然后它工作得很好:

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

Other ideas more than welcome !!!其他想法更受欢迎!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM