From fe1f035d44c656a3aeb4a92fa375e0779b64deba Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Thu, 1 Sep 2016 17:21:54 -0700 Subject: [PATCH] Merge TFS 2064268: ConstrainedLanguage PowerShell should not block nested cmdlet invocation via runspace (#2159) * Merge TFS 2064268: Under UMCI PowerShell should not block nested cmdlet invocation via runspace * Update SessionState.cs Fixed ExecutionContext property name error. --- .../engine/AutomationEngine.cs | 2 -- .../engine/SessionState.cs | 6 +++++- .../engine/SessionStateScope.cs | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/AutomationEngine.cs b/src/System.Management.Automation/engine/AutomationEngine.cs index bc57b4543..743f87271 100644 --- a/src/System.Management.Automation/engine/AutomationEngine.cs +++ b/src/System.Management.Automation/engine/AutomationEngine.cs @@ -93,8 +93,6 @@ namespace System.Management.Automation } InitialSessionState.SetSessionStateDrive(Context, true); - - InitialSessionState.CreateQuestionVariable(Context); } /// diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index 8ac4ae84e..9ced8b5e7 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -351,6 +351,10 @@ namespace System.Management.Automation v = new PSUICultureVariable(); this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + // $? + v = new QuestionMarkVariable(this.ExecutionContext); + this.GlobalScope.SetVariableForce(v, this); + // $ShellId - if there is no runspace config, use the default string string shellId = ExecutionContext.ShellID; @@ -648,4 +652,4 @@ namespace System.Management.Automation } #endregion Errors } // SessionStateInternal class -} \ No newline at end of file +} diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index e30e7b6a3..6429ed71a 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -629,6 +629,24 @@ namespace System.Management.Automation return variable; } // SetVariable + /// + /// Sets a variable to scope without any checks. + /// This is intended to be used only for global scope. + /// + /// PSVariable to set + /// SessionState for variable + /// + internal void SetVariableForce(PSVariable variableToSet, SessionStateInternal sessionState) + { + if (Parent != null) + { + throw new NotImplementedException("SetVariableForce"); + } + + variableToSet.SessionState = sessionState; + GetPrivateVariables()[variableToSet.Name] = variableToSet; + } + /// /// Sets a variable to the given value. ///