From 53ac646cc0f23e2e150f23cabf98ab4c85b5b0db Mon Sep 17 00:00:00 2001 From: dwtaber <38249738+dwtaber@users.noreply.github.com> Date: Wed, 6 Oct 2021 13:43:56 -0400 Subject: [PATCH] Invoke-Command: improve handling of variables with $using: expression (#16113) --- src/System.Management.Automation/engine/parser/ast.cs | 6 ++++-- .../engine/remoting/commands/PSRemotingCmdlet.cs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index 3e1f9ce60a..1f03eb68df 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -1261,7 +1261,8 @@ namespace System.Management.Automation.Language var varAst = ast as VariableExpressionAst; if (varAst != null) { - string varName = varAst.VariablePath.UserPath; + VariablePath varPath = varAst.VariablePath; + string varName = varPath.IsDriveQualified ? $"{varPath.DriveName}_{varPath.UnqualifiedPath}" : $"{varPath.UnqualifiedPath}"; string varSign = varAst.Splatted ? "@" : "$"; string newVarName = varSign + UsingExpressionAst.UsingPrefix + varName; @@ -2329,7 +2330,8 @@ namespace System.Management.Automation.Language // We are done processing the current ParameterAst if (astStartOffset >= endOffset) { break; } - string varName = varAst.VariablePath.UserPath; + VariablePath varPath = varAst.VariablePath; + string varName = varPath.IsDriveQualified ? $"{varPath.DriveName}_{varPath.UnqualifiedPath}" : $"{varPath.UnqualifiedPath}"; string varSign = varAst.Splatted ? "@" : "$"; string newVarName = varSign + UsingExpressionAst.UsingPrefix + varName; diff --git a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs index d4f5ca427a..67d0ced9f1 100644 --- a/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs +++ b/src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs @@ -2374,7 +2374,8 @@ namespace Microsoft.PowerShell.Commands foreach (var varAst in usingVariables) { - string varName = varAst.VariablePath.UserPath; + VariablePath varPath = varAst.VariablePath; + string varName = varPath.IsDriveQualified ? $"{varPath.DriveName}_{varPath.UnqualifiedPath}" : $"{varPath.UnqualifiedPath}"; string paramName = UsingExpressionAst.UsingPrefix + varName; string paramNameWithDollar = "$" + paramName;