Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ internal struct SSHConnection
public string UserName;
public string KeyFilePath;
public int Port;
public string Subsystem;
}

/// <summary>
Expand Down Expand Up @@ -763,6 +764,13 @@ public virtual Hashtable[] SSHConnection
set;
}

/// <summary>
/// This parameter specifies the SSH subsystem to use for the remote connection.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true,
ParameterSetName = InvokeCommandCommand.SSHHostParameterSet)]
public String Subsystem { get; set; }

#endregion

#endregion Properties
Expand Down Expand Up @@ -822,6 +830,7 @@ internal static void ValidateSpecifiedAuthentication(PSCredential credential, st
private const string KeyFilePathParameter = "KeyFilePath";
private const string IdentityFilePathAlias = "IdentityFilePath";
private const string PortParameter = "Port";
private const string SubsystemParameter = "Subsystem";

#endregion

Expand Down Expand Up @@ -915,6 +924,10 @@ internal SSHConnection[] ParseSSHConnectionHashTable()
{
connectionInfo.Port = GetSSHConnectionIntParameter(item[paramName]);
}
else if (paramName.Equals(SubsystemParameter, StringComparison.OrdinalIgnoreCase))
{
connectionInfo.Subsystem = GetSSHConnectionStringParameter(item[paramName]);
}
else
{
throw new PSArgumentException(
Expand Down Expand Up @@ -1385,7 +1398,7 @@ protected void CreateHelpersForSpecifiedSSHComputerNames()
{
ParseSshHostName(computerName, out string host, out string userName, out int port);

var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port);
var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port, this.Subsystem);
var typeTable = TypeTable.LoadDefaultTypeFiles();
var remoteRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace;
var pipeline = CreatePipeline(remoteRunspace);
Expand All @@ -1407,7 +1420,8 @@ protected void CreateHelpersForSpecifiedSSHHashComputerNames()
sshConnection.UserName,
sshConnection.ComputerName,
sshConnection.KeyFilePath,
sshConnection.Port);
sshConnection.Port,
sshConnection.Subsystem);
var typeTable = TypeTable.LoadDefaultTypeFiles();
var remoteRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace;
var pipeline = CreatePipeline(remoteRunspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,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);
var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port, this.Subsystem);
var typeTable = TypeTable.LoadDefaultTypeFiles();

// Use the class _tempRunspace field while the runspace is being opened so that StopProcessing can be handled at that time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,8 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostParameterSet()
userName,
host,
this.KeyFilePath,
port);
port,
Subsystem);
var typeTable = TypeTable.LoadDefaultTypeFiles();
string rsName = GetRunspaceName(index, out int rsIdUnused);
index++;
Expand All @@ -1105,7 +1106,8 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostHashParameterSet()
sshConnection.UserName,
sshConnection.ComputerName,
sshConnection.KeyFilePath,
sshConnection.Port);
sshConnection.Port,
sshConnection.Subsystem);
var typeTable = TypeTable.LoadDefaultTypeFiles();
string rsName = GetRunspaceName(index, out int rsIdUnused);
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,15 @@ private int Port
set;
}

/// <summary>
/// Subsystem to use
/// </summary>
private string Subsystem
{
get;
set;
}

#endregion

#region Constructors
Expand Down Expand Up @@ -1894,6 +1903,7 @@ public SSHConnectionInfo(
this.ComputerName = computerName;
this.KeyFilePath = keyFilePath;
this.Port = DefaultPort;
this.Subsystem = DefaultSubsystem;
}

/// <summary>
Expand All @@ -1903,15 +1913,18 @@ public SSHConnectionInfo(
/// <param name="computerName">Computer Name</param>
/// <param name="keyFilePath">Key File Path</param>
/// <param name="port">Port number for connection (default 22)</param>
/// <param name="subsystem">Subsystem to use (default 'powershell')</param>
public SSHConnectionInfo(
string userName,
string computerName,
string keyFilePath,
int port) : this(userName, computerName, keyFilePath)
int port,
string subsystem) : this(userName, computerName, keyFilePath)
{
ValidatePortInRange(port);

this.Port = (port != 0) ? port : DefaultPort;
this.Subsystem = (String.IsNullOrEmpty(subsystem)) ? DefaultSubsystem : subsystem;
}

#endregion
Expand Down Expand Up @@ -1965,6 +1978,7 @@ internal override RunspaceConnectionInfo InternalCopy()
newCopy.UserName = this.UserName;
newCopy.KeyFilePath = this.KeyFilePath;
newCopy.Port = this.Port;
newCopy.Subsystem = this.Subsystem;

return newCopy;
}
Expand Down Expand Up @@ -2040,14 +2054,14 @@ internal int StartSSHProcess(
}

arguments = (string.IsNullOrEmpty(domainName)) ?
string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" {1}@{2} -p {3} -s powershell", this.KeyFilePath, userName, this.ComputerName, this.Port) :
string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" -l {1}@{2} {3} -p {4} -s powershell", this.KeyFilePath, userName, domainName, this.ComputerName, this.Port);
string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" {1}@{2} -p {3} -s {4}", this.KeyFilePath, userName, this.ComputerName, this.Port, this.Subsystem) :
string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" -l {1}@{2} {3} -p {4} -s {5}", this.KeyFilePath, userName, domainName, this.ComputerName, this.Port, this.Subsystem);
}
else
{
arguments = (string.IsNullOrEmpty(domainName)) ?
string.Format(CultureInfo.InvariantCulture, @"{0}@{1} -p {2} -s powershell", userName, this.ComputerName, this.Port) :
string.Format(CultureInfo.InvariantCulture, @"-l {0}@{1} {2} -p {3} -s powershell", userName, domainName, this.ComputerName, this.Port);
string.Format(CultureInfo.InvariantCulture, @"{0}@{1} -p {2} -s {3}", userName, this.ComputerName, this.Port, this.Subsystem) :
string.Format(CultureInfo.InvariantCulture, @"-l {0}@{1} {2} -p {3} -s {4}", userName, domainName, this.ComputerName, this.Port, this.Subsystem);
}

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(
Expand Down Expand Up @@ -2082,6 +2096,11 @@ private string GetCurrentUserName()
/// </summary>
private const int DefaultPort = 22;

/// <summary>
/// Default value for subsystem
/// </summary>
private const string DefaultSubsystem = "powershell";

#endregion

#region SSH Process Creation
Expand Down