InitialSessionState Class
Updated: April 27, 2016
Applies To: Windows PowerShell
Represents a session state configuration that is used when a runspace is opened. The elements specified here, such as different types of commands, providers, and variables, are accessible each time a runspace that uses this configuration is opened. This class is introduced in Windows PowerShell 2.0.
Assembly: System.Management.Automation (in System.Management.Automation.dll)
| Name | Description | |
|---|---|---|
![]() | InitialSessionState() | Creates a new InitialSessionState object that is empty. This constructor is introduced by Windows PowerShell 2.0. |
| Name | Description | |
|---|---|---|
![]() | ApartmentState | Gets and sets the apartment state of the thread used to run commands in the runspace. This property is introduced in Windows PowerShell 2.0. |
![]() | Assemblies | Gets a collection that contains the assemblies of the initial session state. The host application can use this collection to add assemblies to the session state. This property is introduced in Windows PowerShell 2.0. |
![]() | AuthorizationManager | Gets and sets the authorization manager of the initial session state. This property is introduced in Windows PowerShell 2.0. |
![]() | Commands | Gets a collection that contains the commands, such as cmdlets, scripts, functions, and aliases, of the initial session state. The host application can use this collection to add commands to the session state. This property is introduced in Windows PowerShell 2.0. |
![]() | DisableFormatUpdates | Gets or sets a value that indicates whether updates to the format table are disabled. This includes disabling format table updates through Windows PowerShell cmdlets such as Update-FormatData and Import-Module. Introduced in Windows PowerShell 3.0. |
![]() | EnvironmentVariables | The environment variables. |
![]() | ExecutionPolicy | Specifies the execution policy to be used for this session state instance. |
![]() | Formats | Gets a collection that contains the formatting files of the initial session state. The host application can use this collection to add formatting files to the session state. Formatting files define how .NET Framework objects are displayed by Windows PowerShell. This property is introduced in Windows PowerShell 2.0. |
![]() | LanguageMode | Gets and sets the language mode for runspaces that are opened by using this initial session state. For example, if the language mode is restricted then the runspace will be opened in restricted language mode. This property is introduced in Windows PowerShell 2.0. |
![]() | Modules | Gets the list of modules that can be used to load the default cmdlets, providers, etc., of an initial session state. Introduced in Windows PowerShell 3.0. |
![]() | Providers | Gets a collection that contains the providers of the initial session state. The host application can use this collection to add providers to the session state. This property is introduced in Windows PowerShell 2.0. |
![]() | StartupScripts | The startup scripts. |
![]() | ThreadOptions | Gets and sets a thread option that identifies whether a new thread is created each time a command is run. This property is introduced in Windows PowerShell 2.0. |
![]() | ThrowOnRunspaceOpenError | Gets and sets a Boolean value that indicates whether an exception is thrown while opening the runspace. This property is introduced in Windows PowerShell 2.0. |
![]() | TranscriptDirectory | Specifies the directory to be used for collection session transcripts. |
![]() | Types | Gets a collection that contains the type files of the initial session state. The host application can use this collection to add type files to the session state. Type files are used to extend the .NET Framework types that are used by commands. This property is introduced in Windows PowerShell 2.0. |
![]() | UseFullLanguageModeInDebugger | Gets and sets a Boolean value that indicates whether the Windows PowerShell debugger will use FullLanguage mode while troubleshooting scripts.This property is introduced in Windows PowerShell 2.0. |
![]() | Variables | Gets a collection that contains the variables of the initial session state. The host application can use this collection to add variables to the session state. This property is introduced in Windows PowerShell 2.0. |
| Name | Description | |
|---|---|---|
![]() | Clone() | Creates an exact copy of the current InitialSessionState object. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | Create() | Creates an empty InitialSessionState object that contains none of the commands provided by Windows PowerShell. When this method is used, each element of the session state must be added explicitly.This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | Create(String) | Creates an InitialSessionState object that includes the name of the snap-in or the name of a snap-in collection. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | Create(String[], PSConsoleLoadException) | Creates an InitialSessionState object that includes the names of the snap-ins to load. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | CreateDefault() | Creates an InitialSessionState object that contains the default commands provided by Windows PowerShell. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | CreateDefault2() | Creates a default Windows PowerShell session with the default cmdlets, providers, etc., that are loaded by the modules listed in the Modules property. Introduced in Windows PowerShell 3.0. |
![]() ![]() | CreateFrom(String, PSConsoleLoadException) | Creates an InitialSessionState object from a snap-in at a specified path. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | CreateFrom(String[], PSConsoleLoadException) | Creates an InitialSessionState object from a snap-in at a specified path. This method is introduced in Windows PowerShell 2.0. |
![]() ![]() | CreateFromSessionConfigurationFile(String) | Creates an initial session state from a PSSC configuration file |
![]() ![]() | CreateFromSessionConfigurationFile(String, Func<String, Boolean>) | Creates an initial session state from a PSSC configuration file. |
![]() ![]() | CreateRestricted(SessionCapabilities) | Creates an InitialSessionState object that can be used to create sessions whose Windows PowerShell commands are restricted based on the capabilities of the session. This method is introduced in Windows PowerShell 2.0. |
![]() | Equals(Object) | (Inherited from Object.) |
![]() | Finalize() | (Inherited from Object.) |
![]() | GetHashCode() | (Inherited from Object.) |
![]() | GetType() | (Inherited from Object.) |
![]() | ImportPSModule(IEnumerable<ModuleSpecification>) | Add a list of modules to import when the runspace is created. This element is introduced in Windows PowerShell 5.0. |
![]() | ImportPSModule(String[]) | Adds a list of modules to the initial session state. These modules are imported into the runspace when it is opened. This method is introduced in Windows PowerShell 2.0. |
![]() | ImportPSModulesFromPath(String) | Imports all Windows PowerShell modules from a module path by default. Introduced in Windows PowerShell 3.0. |
![]() | ImportPSSnapIn(String, PSSnapInException) | Adds a snap-in to the initial session state. When the snap-in is added to the collection, the assembly is loaded and all elements (cmdlets, formats, and types) are added to the corresponding elements in the InitialSessionState object. This method is introduced in Windows PowerShell 2.0. |
![]() | MemberwiseClone() | (Inherited from Object.) |
![]() | ToString() | (Inherited from Object.) |
The methods provided by this class can create a session state based on the properties of this class, or on configuration elements defined in a snap-in.
This example shows how to define an initial session state and add two variables to the initial session state.
InitialSessionState iss = InitialSessionState.CreateDefault();
SessionStateVariableEntry var1 = new
SessionStateVariableEntry("test1",
"MyVar1",
"Initial session state MyVar1 test");
iss.Variables.Add(var1);
SessionStateVariableEntry var2 = new
SessionStateVariableEntry("test2",
"MyVar2",
"Initial session state MyVar2 test");
iss.Variables.Add(var2);
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




Notice that in this example, the CreateDefault constructor is used to create an initial session state that includes the default commands provided by Windows PowerShell.