How to pass argument/variable to shell script from powershell using Invoke-SSHStreamShellCommand

JyotiPrakash Mallick 1 Reputation point
2022-01-12T04:29:32.63+00:00

I want to pass a list of variables to a shell script from powershell which is triggering using Invoke-SSHStreamShellCommand.

function remoteConnectEngine($secUsername, $VmPassword, $remoteMachine) {
    $password = ConvertTo-SecureString $VmPassword -AsPlainText -Force;
    $pscredential = New-Object -TypeName System.Management.Automation.PSCredential("$secUsername", $password);
    $triggerJMeterTest = "bash ./startJMeterTest.sh";
    $currentSessionID = New-SSHSession -ComputerName $rm -Credential $pscredential;
         $SSHStream = New-SSHShellStream -Index $currentSessionID.SessionId;
         Invoke-SSHStreamShellCommand -ShellStream $SSHStream -Command $triggerJMeterTest;
}


remoteConnectEngine

Want to pass few arguments to the shellscript triggerJMeterTest

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-01-14T20:02:58.86+00:00

    Can't you just add it to the command?

    $triggerJMeterTest = "bash ./startJMeterTest.sh  $var1  $var2";
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.