Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/System.Management.Automation/engine/AutomationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ internal AutomationEngine(PSHost hostInterface, RunspaceConfiguration runspaceCo
}

InitialSessionState.SetSessionStateDrive(Context, true);

InitialSessionState.CreateQuestionVariable(Context);
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/System.Management.Automation/engine/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ExecutionContext);
this.GlobalScope.SetVariableForce(v, this);

// $ShellId - if there is no runspace config, use the default string
string shellId = ExecutionContext.ShellID;

Expand Down Expand Up @@ -648,4 +652,4 @@ internal ProviderInvocationException NewProviderInvocationException(
}
#endregion Errors
} // SessionStateInternal class
}
}
18 changes: 18 additions & 0 deletions src/System.Management.Automation/engine/SessionStateScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ internal PSVariable SetVariable(string name, object value, bool asValue, bool fo
return variable;
} // SetVariable

/// <summary>
/// Sets a variable to scope without any checks.
/// This is intended to be used only for global scope.
/// </summary>
/// <param name="variableToSet">PSVariable to set</param>
/// <param name="sessionState">SessionState for variable</param>
/// <returns></returns>
internal void SetVariableForce(PSVariable variableToSet, SessionStateInternal sessionState)
{
if (Parent != null)
{
throw new NotImplementedException("SetVariableForce");
}

variableToSet.SessionState = sessionState;
GetPrivateVariables()[variableToSet.Name] = variableToSet;
}

/// <summary>
/// Sets a variable to the given value.
/// </summary>
Expand Down