GeezerVison is showing github.com — Enable setting PSSession Name when using SSHTransport and added Transport property by SteveL-MSFT · Pull Request #5954 · PowerShell/PowerShell
Enable setting PSSession Name when using SSHTransport and added Transport property
#5954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.cs
(4)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -999,6 +999,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
TableControl.Create()
.AddHeader(Alignment.Right, label: "Id", width: 3)
.AddHeader(Alignment.Left, label: "Name", width: 15)
.AddHeader(Alignment.Left, label: "Transport", width: 9)
.AddHeader(Alignment.Left, label: "ComputerName", width: 15)
.AddHeader(Alignment.Left, label: "ComputerType", width: 15)
.AddHeader(Alignment.Left, label: "State", width: 13)
Expand All
@@ -1007,6 +1008,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
.StartRowDefinition()
.AddPropertyColumn("Id")
.AddPropertyColumn("Name")
.AddPropertyColumn("Transport")
.AddPropertyColumn("ComputerName")
.AddPropertyColumn("ComputerType")
.AddPropertyColumn("State")
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -192,6 +192,11 @@ public Runspace Runspace
}
}
/// <summary>
/// Name of the transport used.
/// </summary>
public String Transport => GetTransportName();
#endregion Public Properties
#region Public Methods
Expand Down
Expand Up
@@ -263,7 +268,7 @@ internal PSSession(RemoteRunspace remoteRunspace)
}
else
{
Name = AutoGenerateRunspaceName(Id) ;
Name = "Runspace" + Id ;
remoteRunspace.PSSessionName = Name;
}
Expand Down
Expand Up
@@ -319,34 +324,35 @@ internal PSSession(RemoteRunspace remoteRunspace)
/// Generates and returns the runspace name
/// </summary>
/// <returns>auto generated name</returns>
private string AutoGenerateRunspaceName(int id )
private string GetTransportName( )
{
string sessionIdStr = id.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
if (_remoteRunspace.ConnectionInfo is WSManConnectionInfo)
{
return "WinRM" + sessionIdStr ;
return "WSMan" ;
}
else if (_remoteRunspace.ConnectionInfo is SSHConnectionInfo)
{
return "SSH" + sessionIdStr;
return "SSH";
}
else if (_remoteRunspace.ConnectionInfo is NamedPipeConnectionInfo)
{
return "NamedPipe";
}
else if ((_remoteRunspace.ConnectionInfo is NamedPipeConnectionInfo) ||
(_remoteRunspace.ConnectionInfo is ContainerConnectionInfo))
else if (_remoteRunspace.ConnectionInfo is ContainerConnectionInfo)
{
return "NamedPipe" + sessionIdStr ;
return "Container" ;
}
else if (_remoteRunspace.ConnectionInfo is NewProcessConnectionInfo)
{
return "Process" + sessionIdStr ;
return "Process";
}
else if (_remoteRunspace.ConnectionInfo is VMConnectionInfo)
{
return "Socket" + sessionIdStr ;
return "VMBus" ;
}
else
{
return "Session" + sessionIdStr ;
return "Unknown" ;
}
}
Expand All
@@ -368,15 +374,15 @@ private string GetDisplayShellName(string shell)
#region Static Methods
/// <summary>
/// Generates a unique runspace id and name .
/// Generates a unique runspace id.
/// </summary>
/// <param name="rtnId">Returned Id</param>
/// <returns>Returned name</returns>
internal static String GenerateRunspaceName(out int rtnId)
{
int id = System.Threading.Interlocked.Increment(ref s_seed );
int id = GenerateRunspaceId( );
rtnId = id;
return ComposeRunspaceName(id );
return "Runspace" + id.ToString( );
}
/// <summary>
Expand All
@@ -388,16 +394,6 @@ internal static int GenerateRunspaceId()
return System.Threading.Interlocked.Increment(ref s_seed);
}
/// <summary>
/// Creates a runspace name based on a given Id value.
/// </summary>
/// <param name="id">Integer Id</param>
/// <returns>Runspace name</returns>
internal static string ComposeRunspaceName(int id)
{
return "WinRM" + id.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
}
#endregion
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1308,7 +1308,7 @@ protected virtual void CreateHelpersForSpecifiedComputerNames()
// it can be easily identified if it becomes disconnected and is queried on the server.
int rsId = PSSession.GenerateRunspaceId();
string rsName = (DisconnectedSessionName != null && DisconnectedSessionName.Length > i) ?
DisconnectedSessionName[i] : PSSession.ComposeRunspaceName( rsId);
DisconnectedSessionName[i] : PSSession.GenerateRunspaceName(out rsId);
remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo,
this.Host, this.SessionOption.ApplicationArguments, rsName, rsId);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1073,6 +1073,7 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostParameterSet()
ValidateComputerName(resolvedComputerNames);
var remoteRunspaces = new List<RemoteRunspace>();
int index = 0;
foreach (var computerName in resolvedComputerNames)
{
var sshConnectionInfo = new SSHConnectionInfo(
Expand All
@@ -1081,7 +1082,13 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostParameterSet()
this.KeyFilePath,
this.Port);
var typeTable = TypeTable.LoadDefaultTypeFiles();
remoteRunspaces.Add(RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace);
string rsName = GetRunspaceName(index, out int rsIdUnused);
index++;
remoteRunspaces.Add(RunspaceFactory.CreateRunspace( connectionInfo : sshConnectionInfo,
host : this.Host,
typeTable : typeTable,
applicationArguments : null,
name : rsName) as RemoteRunspace);
}
return remoteRunspaces;
Expand All
@@ -1091,6 +1098,7 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostHashParameterSet()
{
var sshConnections = ParseSSHConnectionHashTable();
var remoteRunspaces = new List<RemoteRunspace>();
int index = 0;
foreach (var sshConnection in sshConnections)
{
var sshConnectionInfo = new SSHConnectionInfo(
Expand All
@@ -1099,7 +1107,13 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostHashParameterSet()
sshConnection.KeyFilePath,
sshConnection.Port);
var typeTable = TypeTable.LoadDefaultTypeFiles();
remoteRunspaces.Add(RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace);
string rsName = GetRunspaceName(index, out int rsIdUnused);
index++;
remoteRunspaces.Add(RunspaceFactory.CreateRunspace( connectionInfo : sshConnectionInfo,
host : this.Host,
typeTable : typeTable,
applicationArguments : null,
name : rsName) as RemoteRunspace);
}
return remoteRunspaces;
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.