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 Trans… · Thatgfsj-contribs/PowerShell@4d86238

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/System.Management.Automation
    • FormatAndOutput/DefaultFormatters
      • PowerShellCore_format_ps1xml.cs
    • engine/remoting
      • client
        • remoterunspaceinfo.cs
      • commands
        • PSRemotingCmdlet.cs
        • newrunspacecommand.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
999999
TableControl.Create()
10001000
.AddHeader(Alignment.Right, label: "Id", width: 3)
10011001
.AddHeader(Alignment.Left, label: "Name", width: 15)
1002+
.AddHeader(Alignment.Left, label: "Transport", width: 9)
10021003
.AddHeader(Alignment.Left, label: "ComputerName", width: 15)
10031004
.AddHeader(Alignment.Left, label: "ComputerType", width: 15)
10041005
.AddHeader(Alignment.Left, label: "State", width: 13)
@@ -1007,6 +1008,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
10071008
.StartRowDefinition()
10081009
.AddPropertyColumn("Id")
10091010
.AddPropertyColumn("Name")
1011+
.AddPropertyColumn("Transport")
10101012
.AddPropertyColumn("ComputerName")
10111013
.AddPropertyColumn("ComputerType")
10121014
.AddPropertyColumn("State")
Collapse file

‎src/System.Management.Automation/engine/remoting/client/remoterunspaceinfo.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/remoting/client/remoterunspaceinfo.cs
+21-25Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ public Runspace Runspace
192192
}
193193
}
194194

195+
/// <summary>
196+
/// Name of the transport used.
197+
/// </summary>
198+
public String Transport => GetTransportName();
199+
195200
#endregion Public Properties
196201

197202
#region Public Methods
@@ -263,7 +268,7 @@ internal PSSession(RemoteRunspace remoteRunspace)
263268
}
264269
else
265270
{
266-
Name = AutoGenerateRunspaceName(Id);
271+
Name = "Runspace" + Id;
267272
remoteRunspace.PSSessionName = Name;
268273
}
269274

@@ -319,34 +324,35 @@ internal PSSession(RemoteRunspace remoteRunspace)
319324
/// Generates and returns the runspace name
320325
/// </summary>
321326
/// <returns>auto generated name</returns>
322-
private string AutoGenerateRunspaceName(int id)
327+
private string GetTransportName()
323328
{
324-
string sessionIdStr = id.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
325-
326329
if (_remoteRunspace.ConnectionInfo is WSManConnectionInfo)
327330
{
328-
return "WinRM" + sessionIdStr;
331+
return "WSMan";
329332
}
330333
else if (_remoteRunspace.ConnectionInfo is SSHConnectionInfo)
331334
{
332-
return "SSH" + sessionIdStr;
335+
return "SSH";
336+
}
337+
else if (_remoteRunspace.ConnectionInfo is NamedPipeConnectionInfo)
338+
{
339+
return "NamedPipe";
333340
}
334-
else if ((_remoteRunspace.ConnectionInfo is NamedPipeConnectionInfo) ||
335-
(_remoteRunspace.ConnectionInfo is ContainerConnectionInfo))
341+
else if (_remoteRunspace.ConnectionInfo is ContainerConnectionInfo)
336342
{
337-
return "NamedPipe" + sessionIdStr;
343+
return "Container";
338344
}
339345
else if (_remoteRunspace.ConnectionInfo is NewProcessConnectionInfo)
340346
{
341-
return "Process" + sessionIdStr;
347+
return "Process";
342348
}
343349
else if (_remoteRunspace.ConnectionInfo is VMConnectionInfo)
344350
{
345-
return "Socket" + sessionIdStr;
351+
return "VMBus";
346352
}
347353
else
348354
{
349-
return "Session" + sessionIdStr;
355+
return "Unknown";
350356
}
351357
}
352358

@@ -368,15 +374,15 @@ private string GetDisplayShellName(string shell)
368374
#region Static Methods
369375

370376
/// <summary>
371-
/// Generates a unique runspace id and name.
377+
/// Generates a unique runspace id.
372378
/// </summary>
373379
/// <param name="rtnId">Returned Id</param>
374380
/// <returns>Returned name</returns>
375381
internal static String GenerateRunspaceName(out int rtnId)
376382
{
377-
int id = System.Threading.Interlocked.Increment(ref s_seed);
383+
int id = GenerateRunspaceId();
378384
rtnId = id;
379-
return ComposeRunspaceName(id);
385+
return "Runspace" + id.ToString();
380386
}
381387

382388
/// <summary>
@@ -388,16 +394,6 @@ internal static int GenerateRunspaceId()
388394
return System.Threading.Interlocked.Increment(ref s_seed);
389395
}
390396

391-
/// <summary>
392-
/// Creates a runspace name based on a given Id value.
393-
/// </summary>
394-
/// <param name="id">Integer Id</param>
395-
/// <returns>Runspace name</returns>
396-
internal static string ComposeRunspaceName(int id)
397-
{
398-
return "WinRM" + id.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
399-
}
400-
401397
#endregion
402398
}
403399
}
Collapse file

‎src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ protected virtual void CreateHelpersForSpecifiedComputerNames()
13081308
// it can be easily identified if it becomes disconnected and is queried on the server.
13091309
int rsId = PSSession.GenerateRunspaceId();
13101310
string rsName = (DisconnectedSessionName != null && DisconnectedSessionName.Length > i) ?
1311-
DisconnectedSessionName[i] : PSSession.ComposeRunspaceName(rsId);
1311+
DisconnectedSessionName[i] : PSSession.GenerateRunspaceName(out rsId);
13121312

13131313
remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo,
13141314
this.Host, this.SessionOption.ApplicationArguments, rsName, rsId);
Collapse file

‎src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs‎

Copy file name to clipboardExpand all lines: src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostParameterSet()
10731073
ValidateComputerName(resolvedComputerNames);
10741074

10751075
var remoteRunspaces = new List<RemoteRunspace>();
1076+
int index = 0;
10761077
foreach (var computerName in resolvedComputerNames)
10771078
{
10781079
var sshConnectionInfo = new SSHConnectionInfo(
@@ -1081,7 +1082,13 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostParameterSet()
10811082
this.KeyFilePath,
10821083
this.Port);
10831084
var typeTable = TypeTable.LoadDefaultTypeFiles();
1084-
remoteRunspaces.Add(RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace);
1085+
string rsName = GetRunspaceName(index, out int rsIdUnused);
1086+
index++;
1087+
remoteRunspaces.Add(RunspaceFactory.CreateRunspace( connectionInfo : sshConnectionInfo,
1088+
host : this.Host,
1089+
typeTable : typeTable,
1090+
applicationArguments : null,
1091+
name : rsName) as RemoteRunspace);
10851092
}
10861093

10871094
return remoteRunspaces;
@@ -1091,6 +1098,7 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostHashParameterSet()
10911098
{
10921099
var sshConnections = ParseSSHConnectionHashTable();
10931100
var remoteRunspaces = new List<RemoteRunspace>();
1101+
int index = 0;
10941102
foreach (var sshConnection in sshConnections)
10951103
{
10961104
var sshConnectionInfo = new SSHConnectionInfo(
@@ -1099,7 +1107,13 @@ private List<RemoteRunspace> CreateRunspacesForSSHHostHashParameterSet()
10991107
sshConnection.KeyFilePath,
11001108
sshConnection.Port);
11011109
var typeTable = TypeTable.LoadDefaultTypeFiles();
1102-
remoteRunspaces.Add(RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace);
1110+
string rsName = GetRunspaceName(index, out int rsIdUnused);
1111+
index++;
1112+
remoteRunspaces.Add(RunspaceFactory.CreateRunspace( connectionInfo : sshConnectionInfo,
1113+
host : this.Host,
1114+
typeTable : typeTable,
1115+
applicationArguments : null,
1116+
name : rsName) as RemoteRunspace);
11031117
}
11041118

11051119
return remoteRunspaces;

0 commit comments

Comments
0 (0)
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.