New-PSTransportOption

创建一个对象,其中包含会话配置的高级选项。

语法

Default (默认值)

New-PSTransportOption
    [-MaxIdleTimeoutSec <Int32>]
    [-ProcessIdleTimeoutSec <Int32>]
    [-MaxSessions <Int32>]
    [-MaxConcurrentCommandsPerSession <Int32>]
    [-MaxSessionsPerUser <Int32>]
    [-MaxMemoryPerSessionMB <Int32>]
    [-MaxProcessesPerSession <Int32>]
    [-MaxConcurrentUsers <Int32>]
    [-IdleTimeoutSec <Int32>]
    [-OutputBufferingMode <OutputBufferingMode>]
    [<CommonParameters>]

说明

New-PSTransportOption cmdlet 创建包含会话配置的传输选项的对象。 可以将对象用作创建或更改会话配置的 cmdlet TransportOption 参数的值,例如 Register-PSSessionConfiguration 和 Set-PSSessionConfiguration cmdlet。

还可以通过编辑 WSMan: 驱动器中的会话配置属性的值来更改传输选项设置。 有关详细信息,请参阅“WSMan 提供程序”。

会话配置选项表示设置在服务器端上的会话值或远程连接的接收端。 在会话创建时,连接的客户端端,或称为发送端,可以设置会话选项值,亦可以在客户端断开或重新连接到会话时进行设置。 除非另有说明,否则设置值冲突时,客户端值优先。 但是,客户端值不能违反会话配置中设置的最大值和配额。

如果没有参数,New-PSTransportOption 将生成一个传输选项对象,该对象具有所有选项的 null 值。 如果省略参数,则该对象具有参数所表示的属性的 null 值。 null 值不会影响会话配置。

有关会话选项的详细信息,请参阅 New-PSSessionOption。 有关会话配置的详细信息,请参阅 about_Session_Configurations

此 cmdlet 已在 Windows PowerShell 3.0 中引入。

示例

示例 1:生成默认传输选项

PS C:\> New-PSTransportOption
ProcessIdleTimeoutSec           :
MaxIdleTimeoutSec               :
MaxSessions                     :
MaxConcurrentCommandsPerSession :
MaxSessionsPerUser              :
MaxMemoryPerSessionMB           :
MaxProcessesPerSession          :
MaxConcurrentUsers              :
IdleTimeoutSec                  :
OutputBufferingMode             :

此命令在没有参数的情况下运行 New-PSTransportOption。 输出显示 cmdlet 生成一个传输选项对象,该对象具有所有属性的 null 值。

示例 2:获取会话配置选项

The first command uses the **New-PSTransportOption** cmdlet to create a transport options object, which it saves in the $t variable. The command uses the *MaxSessions* parameter to increase the maximum number of sessions to 40.
PS C:\> $t = New-PSTransportOption -MaxSessions 40

The second command uses the **Register-PSSessionConfiguration** cmdlet create the ITTasks session configuration. The command uses the *TransportOption* parameter to specify the transport options object in the $t variable.
PS C:\> Register-PSSessionConfiguration -Name ITTasks -TransportOption $t

The third command uses the Get-PSSessionConfiguration cmdlet to get the ITTasks session configurations and the Format-List cmdlet to display all of the properties of the session configuration object in a list. The output shows that the value of the **MaxShells** property of the session configuration is 40.
PS C:\> Get-PSSessionConfiguration -Name ITTasks | Format-List -Property *
Architecture                  : 64
Filename                      : %windir%\system32\pwrshplugin.dll
ResourceUri                   : https://schemas.microsoft.com/powershell/ITTasks
MaxConcurrentCommandsPerShell : 1000
UseSharedProcess              : false
ProcessIdleTimeoutSec         : 0
xmlns                         : https://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
MaxConcurrentUsers            : 5
lang                          : en-US
SupportsOptions               : true
ExactMatch                    : true
RunAsUser                     :
IdleTimeoutms                 : 7200000
PSVersion                     : 3.0
OutputBufferingMode           : Block
AutoRestart                   : false
MaxShells                     : 40
MaxMemoryPerShellMB           : 1024
MaxIdleTimeoutms              : 43200000
SDKVersion                    : 2
Name                          : ITTasks
XmlRenderingType              : text
Capability                    : {Shell}
RunAsPassword                 :
MaxProcessesPerShell          : 15
Enabled                       : True
MaxShellsPerUser              : 25
Permission                    :

此示例演示如何使用传输选项对象设置会话配置选项。

示例 3:设置传输选项

The first command uses the **New-PSTransportOption** cmdlet to create a transport option object. The command uses the *IdleTimeoutSec* parameter to set the **IdleTimeoutSec** property value of the object to one hour (3600 seconds). The command saves the transport objects object in the $t variable.
PS C:\> $t = New-PSTransportOption -IdleTimeoutSec 3600

The second command uses the Set-PSSessionConfiguration cmdlet to change the transport options of the ITTasks session configuration. The command uses the *TransportOption* parameter to specify the transport options object in the $t variable.
PS C:\> Set-PSSessionConfiguration -Name ITTasks -TransportOption $t

The third command uses the New-PSSession cmdlet to create the MyITTasks session on the local computer. The command uses the **ConfigurationName** property to specify the ITTasks session configuration. The command saves the session in the $s variable.Notice that the command does not use the *SessionOption* parameter of **New-PSSession** to set a custom idle time-out for the session. If it did, the idle time-out value set in the session option would take precedence over the idle time-out set in the session configuration.
PS C:\> $s = New-PSSession -Name MyITTasks -ConfigurationName ITTasks

The fourth command uses the Format-List cmdlet to display all properties of the session in the $s variable in a list. The output shows that the session has an idle time-out of one hour (360,000 milliseconds).
PS C:\> $s | Format-List -Property *
State                  : Opened
IdleTimeout            : 3600000
OutputBufferingMode    : Block
ComputerName           : localhost
ConfigurationName      : ITTasks
InstanceId             : 4110c3f5-68ea-40fa-9bbf-04a433dbb02d
Id                     : 1
Name                   : MyITTasks
Availability           : Available
ApplicationPrivateData : {PSVersionTable}
Runspace               : System.Management.Automation.RemoteRunspace

此命令显示在会话配置中设置传输选项对使用该会话配置的会话的影响。

参数

-IdleTimeoutSec

如果远程计算机未从本地计算机接收到任何通信,则决定每个会话保持开放的时长。 这包括心跳信号。 当间隔过期时,会话将关闭。

当用户想要断开连接并重新连接到会话时,空闲超时值非常重要。 仅当会话未超时时,用户才能重新连接。

IdleTimeoutSec 参数对应于会话配置的 IdleTimeoutMs 属性。

以秒为单位输入值。 默认值为 7200 (2 小时)。 最小值为 60 (1 分钟)。 最大值是 WSMan 配置()中 Shell 对象的 WSMan:\\\<ComputerName\>\Shell\IdleTimeout 属性的值。 默认值为 7200000 毫秒(2 小时)。

如果在会话选项和会话配置中设置了空闲超时值,则会话选项中设置的值优先,但不能超过会话配置的 MaxIdleTimeoutMs 属性的值。 若要设置 MaxIdleTimeoutMs 属性的值,请使用 MaxIdleTimeoutSec 参数。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxConcurrentCommandsPerSession

将每个会话中可以同时运行的命令数限制为指定的值。 默认值为 1000。

MaxConcurrentCommandsPerSession 参数对应于会话配置的 MaxConcurrentCommandsPerShell 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxConcurrentUsers

将每个会话中可以同时运行命令的用户数限制为指定的值。 默认值为 5。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxIdleTimeoutSec

将每个会话的空闲超时限制设置为指定值。 默认值为 [Int]::MaxValue (约 25 天)。

当用户想要断开连接并重新连接到会话时,空闲超时值非常重要。 仅当会话未超时时,用户才能重新连接。

MaxIdleTimeoutSec 参数对应于会话配置的 MaxIdleTimeoutMs 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxMemoryPerSessionMB

将每个会话使用的内存限制为指定的值。 输入一个以兆字节为单位的值。 默认值为 1024 兆字节(1 GB)。

MaxMemoryPerSessionMB 参数对应于会话配置的 MaxMemoryPerShellMB 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxProcessesPerSession

将每个会话中运行的进程数限制为指定值。 默认值为 15。

MaxProcessesPerSession 参数对应于会话配置的 MaxProcessesPerShell 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxSessions

限制使用会话配置的会话数。 默认值为 25。

MaxSessions 参数对应于会话配置的 MaxShells 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MaxSessionsPerUser

限制使用会话配置的会话数量,并将其在给定用户凭据下运行的会话数量限制为指定值。 默认值为 25。

当指定此值时,请考虑许多用户可能使用以用户身份运行的凭据。

MaxSessionsPerUser 参数对应于会话配置的 MaxShellsPerUser 属性。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-OutputBufferingMode

确定当输出缓冲区已满时如何在断开连接的会话中管理命令输出。 此参数的可接受值为:

  • 阻止。 当输出缓冲区已满时,将暂停执行,直到缓冲区清空为止。
  • 落。 当输出缓冲区已满时,将继续执行。 保存新输出后,将丢弃最早的输出。
  • 没有。 未指定输出缓冲模式。

会话的 OutputBufferingMode 属性的默认值为 Block。

参数属性

类型:OutputBufferingMode
默认值:None
接受的值:None, Drop, Block
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ProcessIdleTimeoutSec

将每个主机进程的超时限制为指定的值。 默认值 0 表示进程没有超时值。

其他会话配置具有每个进程的超时值。 例如,Microsoft.PowerShell.Workflow 会话配置的每个进程超时值为 28800 秒(8 小时)。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

None

不能通过管道将输入传递给此 cmdlet。

输出

WSManConfigurationOption

备注

  • 会话配置对象的属性因为会话配置设置的选项以及这些选项的值而有所不同。 此外,使用会话配置文件的会话配置具有其他属性。