Skip to content

Fix local remoting #801

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

Merged
merged 7 commits into from
Nov 30, 2018
17 changes: 10 additions & 7 deletions src/PowerShellEditorServices/Session/RunspaceDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -218,13 +217,17 @@ internal static RunspaceDetails CreateFromRunspace(
// ProcessId property isn't on the object, move on.
}

if (runspace.ConnectionInfo.ComputerName != "localhost")
{
runspaceId =
PowerShellContext.ExecuteScriptAndGetItem<Guid>(
"$host.Runspace.InstanceId",
runspace);
// Grab the $host.name which will tell us if we're in a PSRP session or not
string hostName =
PowerShellContext.ExecuteScriptAndGetItem<string>(
"$Host.Name",
runspace,
defaultValue: string.Empty);

// hostname is 'ServerRemoteHost' when the user enters a session.
// ex. Enter-PSSession, Enter-PSHostProcess
if (hostName.Equals("ServerRemoteHost", StringComparison.Ordinal))
{
runspaceLocation = RunspaceLocation.Remote;
connectionString =
runspace.ConnectionInfo.ComputerName +
Expand Down