From d577c4e345369ad45f0b96b54ffe0de8bd5947a5 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 29 Nov 2018 07:47:42 -1000 Subject: [PATCH 1/7] consider "local remoting" as "Remote" --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 072129598..2d1068c92 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -218,7 +218,13 @@ internal static RunspaceDetails CreateFromRunspace( // ProcessId property isn't on the object, move on. } - if (runspace.ConnectionInfo.ComputerName != "localhost") + string hostname = + PowerShellContext.ExecuteScriptAndGetItem( + "$host.name", + runspace, + defaultValue: ""); + + if (hostname == "ServerRemoteHost") { runspaceId = PowerShellContext.ExecuteScriptAndGetItem( From e7a9115d9face392c823d72b377b24da835d50f4 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 29 Nov 2018 07:51:57 -1000 Subject: [PATCH 2/7] comments --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 2d1068c92..351e85f57 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -218,12 +218,15 @@ internal static RunspaceDetails CreateFromRunspace( // ProcessId property isn't on the object, move on. } + // Grab the $host.name which will tell us if we're in a PSRP session or not string hostname = PowerShellContext.ExecuteScriptAndGetItem( "$host.name", runspace, defaultValue: ""); + // hostname is 'ServerRemoteHost' when the user enters a session. + // ex. Enter-PSSession, Enter-PSHostProcess if (hostname == "ServerRemoteHost") { runspaceId = From efdfa7896df06601eca6522d0a702e4ec8b556bb Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Thu, 29 Nov 2018 17:39:07 -1000 Subject: [PATCH 3/7] Update src/PowerShellEditorServices/Session/RunspaceDetails.cs Co-Authored-By: TylerLeonhardt --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 351e85f57..9ee8de616 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -227,7 +227,7 @@ internal static RunspaceDetails CreateFromRunspace( // hostname is 'ServerRemoteHost' when the user enters a session. // ex. Enter-PSSession, Enter-PSHostProcess - if (hostname == "ServerRemoteHost") + if (hostName.Equals("ServerRemoteHost", StringComparison.Ordinal)) { runspaceId = PowerShellContext.ExecuteScriptAndGetItem( From ea22bfc97111b4f09158bf5d3faef586d1900b46 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Thu, 29 Nov 2018 17:39:23 -1000 Subject: [PATCH 4/7] Update src/PowerShellEditorServices/Session/RunspaceDetails.cs Co-Authored-By: TylerLeonhardt --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 9ee8de616..3fa2dfc6c 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -223,7 +223,7 @@ internal static RunspaceDetails CreateFromRunspace( PowerShellContext.ExecuteScriptAndGetItem( "$host.name", runspace, - defaultValue: ""); + defaultValue: string.Empty); // hostname is 'ServerRemoteHost' when the user enters a session. // ex. Enter-PSSession, Enter-PSHostProcess From 7a854609be13992b3962420c9885401f51f93b43 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Thu, 29 Nov 2018 17:39:51 -1000 Subject: [PATCH 5/7] Update src/PowerShellEditorServices/Session/RunspaceDetails.cs Co-Authored-By: TylerLeonhardt --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 3fa2dfc6c..83ce8559b 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -221,7 +221,7 @@ internal static RunspaceDetails CreateFromRunspace( // Grab the $host.name which will tell us if we're in a PSRP session or not string hostname = PowerShellContext.ExecuteScriptAndGetItem( - "$host.name", + "$Host.Name", runspace, defaultValue: string.Empty); From 65a47609472bbd82bd08d4d81c4c59f584851b85 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Thu, 29 Nov 2018 17:40:37 -1000 Subject: [PATCH 6/7] Update src/PowerShellEditorServices/Session/RunspaceDetails.cs Co-Authored-By: TylerLeonhardt --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index 83ce8559b..f4b0840ee 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -219,7 +219,7 @@ internal static RunspaceDetails CreateFromRunspace( } // Grab the $host.name which will tell us if we're in a PSRP session or not - string hostname = + string hostName = PowerShellContext.ExecuteScriptAndGetItem( "$Host.Name", runspace, From af7ac0d88e4752823735ace57962c0800cb4c464 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 29 Nov 2018 17:48:00 -1000 Subject: [PATCH 7/7] addressed Paul's feedback --- src/PowerShellEditorServices/Session/RunspaceDetails.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/PowerShellEditorServices/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Session/RunspaceDetails.cs index f4b0840ee..50ea04e54 100644 --- a/src/PowerShellEditorServices/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Session/RunspaceDetails.cs @@ -193,7 +193,6 @@ internal static RunspaceDetails CreateFromRunspace( Validate.IsNotNull(nameof(runspace), runspace); Validate.IsNotNull(nameof(sessionDetails), sessionDetails); - var runspaceId = runspace.InstanceId; var runspaceLocation = RunspaceLocation.Local; var runspaceContext = RunspaceContext.Original; var versionDetails = PowerShellVersionDetails.GetVersionDetails(runspace, logger); @@ -229,11 +228,6 @@ internal static RunspaceDetails CreateFromRunspace( // ex. Enter-PSSession, Enter-PSHostProcess if (hostName.Equals("ServerRemoteHost", StringComparison.Ordinal)) { - runspaceId = - PowerShellContext.ExecuteScriptAndGetItem( - "$host.Runspace.InstanceId", - runspace); - runspaceLocation = RunspaceLocation.Remote; connectionString = runspace.ConnectionInfo.ComputerName +