Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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.

Namespace:   System.Management.Automation.Runspaces
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

System.Object
  System.Management.Automation.Runspaces.InitialSessionState

public class InitialSessionState

NameDescription
System_CAPS_protmethodInitialSessionState()

Creates a new InitialSessionState object that is empty. This constructor is introduced by Windows PowerShell 2.0.

NameDescription
System_CAPS_pubpropertyApartmentState

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.

System_CAPS_pubpropertyAssemblies

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.

System_CAPS_pubpropertyAuthorizationManager

Gets and sets the authorization manager of the initial session state. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyCommands

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.

System_CAPS_pubpropertyDisableFormatUpdates

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.

System_CAPS_pubpropertyEnvironmentVariables

The environment variables.

System_CAPS_pubpropertyExecutionPolicy

Specifies the execution policy to be used for this session state instance.

System_CAPS_pubpropertyFormats

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.

System_CAPS_pubpropertyLanguageMode

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.

System_CAPS_pubpropertyModules

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.

System_CAPS_pubpropertyProviders

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.

System_CAPS_pubpropertyStartupScripts

The startup scripts.

System_CAPS_pubpropertyThreadOptions

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.

System_CAPS_pubpropertyThrowOnRunspaceOpenError

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.

System_CAPS_pubpropertyTranscriptDirectory

Specifies the directory to be used for collection session transcripts.

System_CAPS_pubpropertyTypes

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.

System_CAPS_pubpropertyUseFullLanguageModeInDebugger

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.

System_CAPS_pubpropertyVariables

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.

NameDescription
System_CAPS_pubmethodClone()

Creates an exact copy of the current InitialSessionState object. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreate()

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.

System_CAPS_pubmethodSystem_CAPS_staticCreate(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.

System_CAPS_pubmethodSystem_CAPS_staticCreate(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.

System_CAPS_pubmethodSystem_CAPS_staticCreateDefault()

Creates an InitialSessionState object that contains the default commands provided by Windows PowerShell. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateDefault2()

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.

System_CAPS_pubmethodSystem_CAPS_staticCreateFrom(String, PSConsoleLoadException)

Creates an InitialSessionState object from a snap-in at a specified path. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateFrom(String[], PSConsoleLoadException)

Creates an InitialSessionState object from a snap-in at a specified path. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticCreateFromSessionConfigurationFile(String)

Creates an initial session state from a PSSC configuration file

System_CAPS_pubmethodSystem_CAPS_staticCreateFromSessionConfigurationFile(String, Func<String, Boolean>)

Creates an initial session state from a PSSC configuration file.

System_CAPS_pubmethodSystem_CAPS_staticCreateRestricted(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.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodImportPSModule(IEnumerable<ModuleSpecification>)

Add a list of modules to import when the runspace is created.

This element is introduced in Windows PowerShell 5.0.

System_CAPS_pubmethodImportPSModule(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.

System_CAPS_pubmethodImportPSModulesFromPath(String)

Imports all Windows PowerShell modules from a module path by default. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodImportPSSnapIn(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.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(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);

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.

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: