Creates an object that contains advanced options for a PSSession.

Syntax

  Copy Code
New-PSSessionOption [-ApplicationArguments <PSPrimitiveDictionary>] [-CancelTimeOut <int>] [-Culture <CultureInfo>] [-IdleTimeOut <int>] [-MaximumReceivedDataSizePerCommand <int>] [-MaximumReceivedObjectSize <int>] [-MaximumRedirection <int>] [-NoCompression] [-NoEncryption] [-NoMachineProfile] [-OpenTimeOut <int>] [-OperationTimeOut <int>] [-ProxyAccessType {<None> | <IEConfig> | <WinHttpConfig> | <AutoDetect> | <NoProxyServer>}] [-ProxyAuthentication {<Default> | <Basic> | <Negotiate> | <NegotiateWithImplicitCredential> | <Credssp> | <Digest> | <Kerberos>}] [-ProxyCredential <PSCredential>] [-SkipCACheck] [-SkipCNCheck] [-SkipRevocationCheck] [-UICulture <CultureInfo>] [-UseUTF16] [<CommonParameters>]

Description

The New-PSSessionOption cmdlet creates an object that contains advanced options for a PSSession. You can use the object as the value of the SessionOption parameter of cmdlets that create a PSSession, such as New-PSSession, Enter-PSSession, and Invoke-Command.

Without parameters, New-PSSessionOption generates an object that contains the default values for all of the options. Because all of the properties can be edited, you can use the resulting object as a template, and create standard option objects for your enterprise.

Parameters

-ApplicationArguments <PSPrimitiveDictionary>

Specifies a primitive dictionary that is sent to the remote session. Commands and scripts in the remote session, including startup scripts in the session configuration, can find this dictionary in the ApplicationArguments property of the $PSSenderInfo automatic variable. You can use this parameter to send data to the remote session.

A primitive dictionary is like a hash table, but it contains keys that are case-insensitive strings and values that can be serialized and deserialized during Windows PowerShell remoting handshakes. If you enter a hash table for the value of this parameter, Windows PowerShell converts it to a primitive dictionary.

For more information, see about_Hash_Tables, about_Session_Configurations, and about_Automatic_Variables.

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CancelTimeOut <int>

Determines how long Windows PowerShell waits for a cancel operation (CTRL + C) to complete before terminating it. Enter a value in milliseconds.

The default value is 60000 (one minute). A value of 0 (zero) means no timeout; the command continues indefinitely.

Required?

false

Position?

named

Default Value

60000

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Culture <CultureInfo>

Specifies the culture to use for the PSSession. Enter a culture name in <languagecode2>-<country/regioncode2> format, such as "ja-jP", a variable that contains a CultureInfo object, or a command that gets a CultureInfo object, such as "Get-Culture".

The default value is $null, and the culture that is set in the operating system when the PSSession is created is used in the PSSession.

Required?

false

Position?

named

Default Value

Current culture

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-IdleTimeOut <int>

Determines how long the PSSession stays open if the remote computer does not receive any communication from the local computer, including the heartbeat signal. When the interval expires, the PSSession closes.

Enter a value in milliseconds. The default value is 240000 (4 minutes). The minimum value is 60000 (1 minute).

If both the local and remote computers specify an idle timeout value, the PSSession uses the shorter timeout value. The local computer can set an idle timeout value by using this parameter or by setting an idle timeout in the $PSSessionOption preference variable. The remote computer can specify an idle timeout value in the WS-Management configuration (WSMAN:\localhost\shell\idletimeout).

Required?

false

Position?

named

Default Value

240000

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-MaximumReceivedDataSizePerCommand <int>

Specifies the maximum number of bytes that the local computer can receive from the remote computer in a single command. Enter a value in bytes. By default, there is no data size limit.

This option is designed to protect the resources on the client computer.

Required?

false

Position?

named

Default Value

No limit

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-MaximumReceivedObjectSize <int>

Specifies the maximum size of an object that the local computer can receive from the remote computer. Enter a value in bytes. By default, there is no data size limit.

This option is designed to protect the resources on the client computer.

Required?

false

Position?

named

Default Value

No limit

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-MaximumRedirection <int>

Determines how many times Windows PowerShell redirects a connection to an alternate Uniform Resource Identifier (URI) before the connection fails. The default value is 5. A value of 0 (zero) prevents all redirection.

This option is used in the PSSession only when the AllowRedirection parameter is used in the command that creates the PSSession.

Required?

false

Position?

named

Default Value

5

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-NoCompression

Turns off packet compression in the PSSession. Compression uses more processor cycles, but it makes transmission faster.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-NoEncryption

Turns off data encryption.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-NoMachineProfile

Prevents loading the user's Windows user profile. As a result, the PSSession might be created faster, but user-specific registry settings, items such as environment variables, and certificates are not available in the PSSession.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-OpenTimeOut <int>

Determines how long the client computer waits for the session connection to be established. When the interval expires, the command to establish the connection fails. Enter a value in milliseconds.

The default value is 180000 (3 minutes). A value of 0 (zero) means no time-out; the command continues indefinitely.

Required?

false

Position?

named

Default Value

180000

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-OperationTimeOut <int>

Determines the maximum time that any operation in the PSSession can run. When the interval expires, the operation fails. Enter a value in milliseconds.

The default value is 180000 (3 minutes). A value of 0 (zero) means no time-out; the operation continues indefinitely.

Required?

false

Position?

named

Default Value

180000

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ProxyAccessType <ProxyAccessType>

Determines which mechanism is used to resolve the host name. Valid values are IEConfig, WinHttpConfig, AutoDetect, NoProxyServer and None. The default value is None.

For information about the values of this parameter, see the description of the System.Management.Automation.Remoting.ProxyAccessType enumeration in the MSDN (Microsoft Developer Network) Library at http://go.microsoft.com/fwlink/?LinkId=144756.

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ProxyAuthentication <AuthenticationMechanism>

Specifies the authentication method that is used for proxy resolution. Valid values are Basic, Digest, and Negotiate. The default value is Negotiate.

For information about the values of this parameter, see the description of the System.Management.Automation.Runspaces.AuthenticationMechanism enumeration in the MSDN library at http://go.microsoft.com/fwlink/?LinkID=144382.

Required?

false

Position?

named

Default Value

Negotiate

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ProxyCredential <PSCredential>

Specifies the credentials to use for proxy authentication. Enter a variable that contains a PSCredential object or a command that gets a PSCredential object, such as Get-Credential. If this option is not set, no credentials are specified.

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SkipCACheck

Specifies that when connecting over HTTPS, the client does not validate that the server certificate is signed by a trusted certification authority (CA).

Use this option only when the remote computer is trusted by using another mechanism, such as when the remote computer is part of a network that is physically secure and isolated or when the remote computer is listed as a trusted host in a WinRM configuration.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SkipCNCheck

Specifies that the certificate common name (CN) of the server does not need to match the hostname of the server. This option is used only in remote operations that use the HTTPS protocol.

Use this option only for trusted computers.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SkipRevocationCheck

Does not validate the revocation status of the server certificate.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-UICulture <CultureInfo>

Specifies the UI culture to use for the PSSession.

Enter a culture name in <languagecode2>-<country/regioncode2> format, such as "ja-jP", a variable that contains a CultureInfo object, or a command that gets a CultureInfo object, such as Get-Culture.

The default value is $null, and the UI culture that is set in the operating system when the PSSession is created is used in the PSSession.

Required?

false

Position?

named

Default Value

Current UI culture

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-UseUTF16

Encode the request in UTF16 format rather than UTF8 format.

Required?

false

Position?

named

Default Value

False (UTF8 encoding)

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This command supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters.

Inputs and Outputs

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.

Inputs

None

You cannot pipe input to this cmdlet.

Outputs

System.Management.Automation.Remoting.PSSessionOption

Notes

If the SessionOption parameter is not used in a command to create a PSSession, the session options are determined by the property values of the $PSSessionOption preference variable, if it is set. For more information about the $PSSessionOption variable, see about_Preference_Variables.

Example 1

  Copy Code
C:\PS>New-PSSessionOption


MaximumConnectionRedirectionCount : 5
NoCompression					 : False
NoMachineProfile				: False
ProxyAccessType				 : IEConfig
ProxyAuthentication			 : Negotiate
ProxyCredential				 :
SkipCACheck					 : False
SkipCNCheck					 : False
SkipRevocationCheck			 : False
OperationTimeout				: 00:03:00
NoEncryption					: False
UseUTF16						: False
Culture						 :
UICulture						 :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize		 :
ApplicationArguments			:
OpenTimeout					 : 00:03:00
CancelTimeout					 : 00:01:00
IdleTimeout					 : 00:04:00

Description
-----------
This command creates a session option object with all of the default values.






Example 2

  Copy Code
C:\PS>$pso = new-pssessionoption -Culture "fr-fr" -MaximumReceivedObjectSize 10MB

C:\PS> new-pssession -computerName Server01 -SessionOption $pso

Description
-----------
This example shows how to use a session option object to configure a session.

The first command creates a new session option object and saves it in the value of the $pso variable.

The second command uses the New-PSSession cmdlet to create a PSSession on the Server01 remote computer. The command uses the session option object in the value of the $pso variable as the value of the SessionOption parameter of the command.






Example 3

  Copy Code
C:\PS>enter-pssession -computername Server01 -sessionOption (new-pssessionoption -noEncryption -noCompression)

Description
-----------
This command uses the Enter-PSSession cmdlet to start an interactive session with the Server01 computer. The value of the SessionOption parameter is a New-PSSessionOption command with the NoEncryption and NoCompression switch parameters.

The New-PSSessionOption command is enclosed in parentheses to make sure that it runs before the Enter-PSSession command.






Example 4

  Copy Code
C:\PS>$a = new-pssessionoption


MaximumConnectionRedirectionCount : 5
NoCompression					 : False
NoMachineProfile				: False
ProxyAccessType				 : IEConfig
ProxyAuthentication			 : Negotiate
ProxyCredential				 :
SkipCACheck					 : False
SkipCNCheck					 : False
SkipRevocationCheck			 : False
OperationTimeout				: 00:03:00
NoEncryption					: False
UseUTF16						: False
Culture						 :
UICulture						 :
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize		 :
ApplicationArguments			:
OpenTimeout					 : 00:03:00
CancelTimeout					 : 00:01:00
IdleTimeout					 : 00:04:00

C:\PS> $a.UICulture = (get-UICulture)
C:\PS> $a.OpenTimeout = (new-timespan -minutes 4)
C:\PS> $a.MaximumConnectionRedirectionCount = 1

C:\PS> $a

MaximumConnectionRedirectionCount : 1
NoCompression					 : False
NoMachineProfile				: False
ProxyAccessType				 : IEConfig
ProxyAuthentication			 : Negotiate
ProxyCredential				 :
SkipCACheck					 : False
SkipCNCheck					 : False
SkipRevocationCheck			 : False
OperationTimeout				: 00:03:00
NoEncryption					: False
UseUTF16						: False
Culture						 :
UICulture						 : en-US
MaximumReceivedDataSizePerCommand :
MaximumReceivedObjectSize		 :
ApplicationArguments			:
OpenTimeout					 : 00:04:00
CancelTimeout					 : 00:01:00
IdleTimeout					 : 00:04:00

Description
-----------
This example demonstrates that you can edit the session option object. All properties have read/write values.

Use this method to create a standard session object for your enterprise, and then create customized versions of it for particular uses.






Example 5

  Copy Code
C:\PS>$PSSessionOption = New-PSSessionOption -OpenTimeOut 120000

Description
-----------
This command creates a $PSSessionOption preference variable. 

When the $PSSessionOption preference variable exists in the session, it establishes default values for options in the PSSessions that are created by using the New-PSSession, Enter-PSSession, and Invoke-Command cmdlets.

To make the $PSSessionOption variable available in all sessions, add it to your Windows PowerShell session and to your Windows PowerShell profile.

For more information about the $PSSessionOption variable, see about_Preference_Variables. For more information about profiles, see about_Profiles.






Example 6

  Copy Code
C:\PS>$skipCN = new-pssessionoption -SkipCNCheck

C:\PS> new-pssession -computername 171.09.21.207 -UseSSL -credential domain01\user01 -sessionOption $skipCN

Description
-----------
This example shows how to use a SessionOption object to fulfill the requirements for a remote session configuration.

The first command uses the New-PSSessionOption cmdlet to create a session option object with the SkipCNCheck property. The command saves the resulting session object in the $skipCN variable.

The second command uses the New-PSSession cmdlet to create a new PSSession on a remote computer. The $skipCN check variable is used in the value of the SessionOption parameter. 

Because the computer is identified by its IP address, the value of the ComputerName parameter does not match any of the common names in the certificate used for Secure Sockets Layer (SSL). As a result, the SkipCNCheck option is required.






Example 7

  Copy Code
C:\PS>$team = @{Team="IT"; Use="Testing"}

C:\PS> $teamOption = new-pssessionOption -applicationArguments $team

C:\PS> $s = new-pssession -computername Server01 -SessionOption $teamOption

C:\PS> invoke-command -session $s {$PSSenderInfo.applicationArguments}

Name				 Value
----				 -----
Team				 IT
Use				Testing
PSVersionTable	 {CLRVersion, BuildVersion, PSVersion, WSManStackVersion...}

C:\PS> invoke-command -session $s {if ($PSSenderInfo.ApplicationArguments.Use -ne "Testing") 
{.\logFiles.ps1} else {"Just testing."}}
Just testing.

Description
-----------
This example shows how to use the ApplicationArguments parameter of the New-PSSessionOption cmdlet to make additional data available to the remote session. 

The first command creates a hash table with two keys, Team and Use. The command saves the hash table in the $team variable. (For more information about hash tables, see about_Hash_Tables.)

The second command uses the ApplicationArguments parameter of the New-PSSessionOption cmdlet to create a session option object that contains the data in the $team variable. The command saves the session option object in the $teamOption variable.

When New-PSSessionOption creates the session option object, it automatically converts the hash table in the value of the ApplicationArguments parameter to a primitive dictionary so the data can be reliably transmitted to the remote session.

The third command uses the New-PSSession cmdlet to start a PSSession on the Server01 computer. It uses the SessionOption parameter to include the options in the $teamOption variable.

The fourth command demonstrates that the data in the $team variable is available to commands in the remote session. The data appears in the ApplicationArguments property of the $PSSenderInfo automatic variable. 

The fifth command shows how the data might be used. The command uses the Invoke-Command cmdlet to run a script only when the value of the Use property is not "Testing". When the value of Use is "Testing", the command returns "Just testing."






See Also