-1

I guess I have it 90% correct, but a small part seems to be missing...

I have no problem opening a remote session from Windows -> Linux (host) No problem passing a command either. 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

Philippe
  • 103
  • 1
  • 1
  • 8

1 Answers1

0

My answer is a workaroud for the time being. Bugs probably remain in Powershell remoting :-)

1) Adapt your test.sh file to turn it into a Powershell script: test.ps1 (hope you don't have complex scripts)

2) Then it works just fine:

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

Other ideas more than welcome !!!

Philippe
  • 103
  • 1
  • 1
  • 8