Exemple #1
0
        /// <summary>
        /// Add any special variables to the session state variable table. This routine
        /// must be called at construction time or if the variable table is reset.
        /// </summary>
        internal void InitializeSessionStateInternalSpecialVariables(bool clearVariablesTable)
        {
            if (clearVariablesTable)
            {
                // Clear the variable table
                GlobalScope.Variables.Clear();

                // Add in the per-scope default variables.
                GlobalScope.AddSessionStateScopeDefaultVariables();
            }

            // Set variable $Error
            PSVariable errorvariable = new PSVariable("Error", new ArrayList(), ScopedItemOptions.Constant);

            GlobalScope.SetVariable(errorvariable.Name, errorvariable, false, false, this, fastPath: true);

            // Set variable $PSDefaultParameterValues
            Collection <Attribute> attributes = new Collection <Attribute>();

            attributes.Add(new ArgumentTypeConverterAttribute(typeof(System.Management.Automation.DefaultParameterDictionary)));
            PSVariable psDefaultParameterValuesVariable = new PSVariable(SpecialVariables.PSDefaultParameterValues,
                                                                         new DefaultParameterDictionary(),
                                                                         ScopedItemOptions.None, attributes,
                                                                         RunspaceInit.PSDefaultParameterValuesDescription);

            GlobalScope.SetVariable(psDefaultParameterValuesVariable.Name, psDefaultParameterValuesVariable, false, false, this, fastPath: true);
        }