Skip to content

Commit fe1f035

Browse files
PaulHigindaxian-dbw
authored andcommitted
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.
1 parent 1d1c8b7 commit fe1f035

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/System.Management.Automation/engine/AutomationEngine.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ internal AutomationEngine(PSHost hostInterface, RunspaceConfiguration runspaceCo
9393
}
9494

9595
InitialSessionState.SetSessionStateDrive(Context, true);
96-
97-
InitialSessionState.CreateQuestionVariable(Context);
9896
}
9997

10098
/// <summary>

src/System.Management.Automation/engine/SessionState.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ internal void InitializeFixedVariables()
351351
v = new PSUICultureVariable();
352352
this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);
353353

354+
// $?
355+
v = new QuestionMarkVariable(this.ExecutionContext);
356+
this.GlobalScope.SetVariableForce(v, this);
357+
354358
// $ShellId - if there is no runspace config, use the default string
355359
string shellId = ExecutionContext.ShellID;
356360

@@ -648,4 +652,4 @@ internal ProviderInvocationException NewProviderInvocationException(
648652
}
649653
#endregion Errors
650654
} // SessionStateInternal class
651-
}
655+
}

src/System.Management.Automation/engine/SessionStateScope.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,24 @@ internal PSVariable SetVariable(string name, object value, bool asValue, bool fo
629629
return variable;
630630
} // SetVariable
631631

632+
/// <summary>
633+
/// Sets a variable to scope without any checks.
634+
/// This is intended to be used only for global scope.
635+
/// </summary>
636+
/// <param name="variableToSet">PSVariable to set</param>
637+
/// <param name="sessionState">SessionState for variable</param>
638+
/// <returns></returns>
639+
internal void SetVariableForce(PSVariable variableToSet, SessionStateInternal sessionState)
640+
{
641+
if (Parent != null)
642+
{
643+
throw new NotImplementedException("SetVariableForce");
644+
}
645+
646+
variableToSet.SessionState = sessionState;
647+
GetPrivateVariables()[variableToSet.Name] = variableToSet;
648+
}
649+
632650
/// <summary>
633651
/// Sets a variable to the given value.
634652
/// </summary>

0 commit comments

Comments
 (0)