GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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.

Sign up for GitHub

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

Merged
Travis Plunk (TravisEz13) merged 4 commits into PowerShell:master from SteveL-MSFT:sshconnection-name
Feb 4, 2018

Uh oh!

There was an error while loading. Please reload this page.

Merged

Enable setting PSSession Name when using SSHTransport and added Transport property #5954

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
8df7e30
use correct overload to set name for pssession
SteveL-MSFT Jan 19, 2018
5c8432e
changed the generated pssession name to have appropriate transport pr…
SteveL-MSFT Jan 19, 2018
d49dea6
refactor runspace name generation code
SteveL-MSFT Jan 31, 2018
9a96af3
address Paul's feedback
SteveL-MSFT Feb 1, 2018
File filter
Filter by extension

Clear filters
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
Diff view

There are no files selected for viewing

2 changes: 2 additions & 0 deletions 2 ...m.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
Show comments
View file
Open in desktop
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
46 changes: 21 additions & 25 deletions 46 src/System.Management.Automation/engine/remoting/client/remoterunspaceinfo.cs
Show comments
View file
Open in desktop
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
}
}
2 changes: 1 addition & 1 deletion 2 src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs
Show comments
View file
Open in desktop
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
18 changes: 16 additions & 2 deletions 18 src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs
Show comments
View file
Open in desktop
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.