I have build a powershell script to run commands remotely. Nothing really to it, just open a session, invoke-command, do some logging and exit. That script is called remoteExecute.ps1
It is working fine as intended when I run it the outputs are what to be expected.
I'm having trouble running shell scripts using bash command. I have a server on which I installed WSL2 Linux distribution Ubuntu 20. When I log in on the server I can open a terminal window and run the bash command to execute a shell script without issues.
BUT, when I call this remotely from the powershell script it returns an error:
PS D:\batch> .\remoteExecute.ps1 -computer myserver -command "bash -c /mnt/c/somefile.sh"**
Opening new section on remote computer myserver
**The term 'bash -c myshellscript.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 -c /mnt/c/somefile.sh:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : myserver
Executed: 'bash -c /mnt/csomefile.sh'
Closed session
Powershell version used on both machines is v7.1 and I defaulted it to windows by setting this registry key
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -name Shell -Value 'C:\Program Files\PowerShell\7\PowerShell.exe -noExit'
What am I missing?