diff --git a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
index b60f3131f24..29de22a0536 100644
--- a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
@@ -753,6 +753,18 @@ public override SwitchParameter SSHTransport
set { base.SSHTransport = value; }
}
+ ///
+ /// This parameter allows you to specify a custom executable name to use for the SSH transport. The executable must be on the path.
+ ///
+ [Parameter(ParameterSetName = PSRemotingBaseCmdlet.SSHHostParameterSet)]
+ [Parameter(ParameterSetName = InvokeCommandCommand.FilePathSSHHostParameterSet)]
+ public override string SSHTransportPath
+ {
+ get { return base.SSHTransportPath; }
+
+ set { base.SSHTransportPath = value; }
+ }
+
///
/// Hashtable array containing SSH connection parameters for each remote target
/// ComputerName (Alias: HostName) (required)
diff --git a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs
index bbb2056189c..48a9a182af1 100644
--- a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs
@@ -769,6 +769,16 @@ public virtual SwitchParameter SSHTransport
set;
}
+ ///
+ /// Gets or sets a custom executable name to use for the SSH transport. The executable must be on the path.
+ ///
+ [Parameter(ParameterSetName = PSRemotingBaseCmdlet.SSHHostParameterSet)]
+ public virtual string SSHTransportPath
+ {
+ get;
+ set;
+ }
+
///
/// Hashtable array containing SSH connection parameters for each remote target
/// ComputerName (Alias: HostName) (required)
diff --git a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs
index cbc5f82742b..b2b041eba41 100644
--- a/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs
@@ -1262,7 +1262,7 @@ private RemoteRunspace GetRunspaceForContainerSession()
private RemoteRunspace GetRunspaceForSSHSession()
{
ParseSshHostName(HostName, out string host, out string userName, out int port);
- var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port, this.Subsystem);
+ var sshConnectionInfo = new SSHConnectionInfo(userName, host, KeyFilePath, port, Subsystem, SSHTransportPath);
var typeTable = TypeTable.LoadDefaultTypeFiles();
// Use the class _tempRunspace field while the runspace is being opened so that StopProcessing can be handled at that time.
diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
index 9debc89ce76..21131208073 100644
--- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
+++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
@@ -1892,6 +1892,15 @@ private string Subsystem
set;
}
+ ///
+ /// Gets or sets the name of the ssh executable to use.
+ ///
+ private string SshPath
+ {
+ get;
+ set;
+ }
+
#endregion
#region Constructors
@@ -1960,6 +1969,26 @@ public SSHConnectionInfo(
this.Port = port;
this.Subsystem = (string.IsNullOrEmpty(subsystem)) ? DefaultSubsystem : subsystem;
}
+
+ ///
+ /// Initializes a new instance of the SSHConnectionInfo class.
+ ///
+ /// User Name.
+ /// Computer Name.
+ /// Key File Path.
+ /// Port number for connection (default 22).
+ /// Subsystem to use (default 'powershell').
+ /// Name or path to ssh executable (default 'ssh' or 'ssh.exe')'.
+ public SSHConnectionInfo(
+ string userName,
+ string computerName,
+ string keyFilePath,
+ int port,
+ string subsystem,
+ string sshPath) : this(userName, computerName, keyFilePath, port, subsystem)
+ {
+ this.SshPath = sshPath;
+ }
#endregion
@@ -2016,6 +2045,7 @@ internal override RunspaceConnectionInfo InternalCopy()
newCopy.KeyFilePath = this.KeyFilePath;
newCopy.Port = this.Port;
newCopy.Subsystem = this.Subsystem;
+ newCopy.SshPath = this.SshPath;
return newCopy;
}
@@ -2049,15 +2079,19 @@ internal int StartSSHProcess(
out StreamReader stdErrReaderVar)
{
string filePath = string.Empty;
-#if UNIX
- const string sshCommand = "ssh";
-#else
- const string sshCommand = "ssh.exe";
-#endif
+ if (SshPath == null)
+ {
+ #if UNIX
+ SshPath = "ssh";
+ #else
+ SshPath = "ssh.exe";
+ #endif
+ }
+
var context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
if (context != null)
{
- var cmdInfo = context.CommandDiscovery.LookupCommandInfo(sshCommand, CommandOrigin.Internal) as ApplicationInfo;
+ var cmdInfo = context.CommandDiscovery.LookupCommandInfo(SshPath, CommandOrigin.Internal) as ApplicationInfo;
if (cmdInfo != null)
{
filePath = cmdInfo.Path;