New PSSessionOption - PowerShell
Overview
New-PSSessionOption creates a new session option object that defines custom configuration settings for remote PowerShell sessions. These options can be used to modify the behavior of remote sessions, such as setting the maximum number of connections, enabling SSL encryption, or specifying a connection timeout.
Syntax
New-PSSessionOption [-Name] <string> [-Type] <string> [-Value] <object> [-PassThru]
Options/Flags
- -Name: Specifies the name of the session option.
- -Type: Specifies the type of session option. Valid values are “ConnectionInfo”, “Proxy”, “Security”, “Session”, “View”, and “Custom”.
- -Value: Specifies the value of the session option. The value must be a valid value for the specified type.
- -PassThru: Returns the new session option object.
Examples
Creating a basic session option
New-PSSessionOption -Name SessionTimeout -Type Session -Value 3600
Creating a session option with a custom type
New-PSSessionOption -Name MyCustomOption -Type Custom -Value "My custom value"
Creating a session option and passing it to a New-PSSession cmdlet
$sessionOption = New-PSSessionOption -Name SessionTimeout -Type Session -Value 3600
New-PSSession -ComputerName MyComputer -SessionOption $sessionOption
Common Issues
Option not recognized
If you receive an error message indicating that the option you are trying to set is not recognized, check that you have specified the correct type for the session option.
Invalid value
If you receive an error message indicating that the value you are trying to set is invalid, check that the value is a valid value for the specified type.
Integration
New-PSSessionOption can be combined with other PowerShell commands to create custom session configurations for remote PowerShell sessions. For example, you can use New-PSSessionOption to create a session option that sets the maximum number of connections to a remote computer, and then pass that session option to a New-PSSession cmdlet to create a new remote session with the specified maximum number of connections.
Related Commands
- New-PSSession
- Remove-PSSessionOption