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

问题描述 投票:-1回答: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

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

谢谢,菲利普

powershell sh powershell-remoting scriptblock
1个回答
0
投票

我的回答是暂时的工作。错误可能仍然存在于Powershell远程处:-)

1)调整test.sh文件,将其转换为Powershell脚本:test.ps1(希望您没有复杂的脚本)

2)然后它工作得很好:

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

其他想法超过欢迎!

© www.soinside.com 2019 - 2024. All rights reserved.