From 10be3a242331a544fe6bbead764cdb5c233fe710 Mon Sep 17 00:00:00 2001 From: PaulHigin Date: Thu, 1 Sep 2016 10:47:51 -0700 Subject: [PATCH 1/2] Merge TFS 2064268: Under UMCI PowerShell should not block nested cmdlet invocation via runspace --- .../engine/AutomationEngine.cs | 2 -- .../engine/SessionState.cs | 4 ++++ .../engine/SessionStateScope.cs | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/AutomationEngine.cs b/src/System.Management.Automation/engine/AutomationEngine.cs index bc57b454355..743f87271d6 100644 --- a/src/System.Management.Automation/engine/AutomationEngine.cs +++ b/src/System.Management.Automation/engine/AutomationEngine.cs @@ -93,8 +93,6 @@ internal AutomationEngine(PSHost hostInterface, RunspaceConfiguration runspaceCo } 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 8ac4ae84ee6..ab7358cb48d 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -351,6 +351,10 @@ internal void InitializeFixedVariables() v = new PSUICultureVariable(); this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + // $? + v = new QuestionMarkVariable(this._context); + this.GlobalScope.SetVariableForce(v, this); + // $ShellId - if there is no runspace config, use the default string string shellId = ExecutionContext.ShellID; diff --git a/src/System.Management.Automation/engine/SessionStateScope.cs b/src/System.Management.Automation/engine/SessionStateScope.cs index e30e7b6a303..6429ed71a85 100644 --- a/src/System.Management.Automation/engine/SessionStateScope.cs +++ b/src/System.Management.Automation/engine/SessionStateScope.cs @@ -629,6 +629,24 @@ internal PSVariable SetVariable(string name, object value, bool asValue, bool fo 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. /// From 7a9b34da0a3c6f833bc7f7951ffe21eb047fe3f4 Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Thu, 1 Sep 2016 14:55:25 -0700 Subject: [PATCH 2/2] Update SessionState.cs Fixed ExecutionContext property name error. --- src/System.Management.Automation/engine/SessionState.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index ab7358cb48d..9ced8b5e7ec 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -352,7 +352,7 @@ internal void InitializeFixedVariables() this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); // $? - v = new QuestionMarkVariable(this._context); + v = new QuestionMarkVariable(this.ExecutionContext); this.GlobalScope.SetVariableForce(v, this); // $ShellId - if there is no runspace config, use the default string @@ -652,4 +652,4 @@ internal ProviderInvocationException NewProviderInvocationException( } #endregion Errors } // SessionStateInternal class -} \ No newline at end of file +}