当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 获取 PSSessionConfiguration (Microsoft.PowerShell.Core)

作者:精品下载站 日期:2024-12-14 02:15:39 浏览:15 分类:玩电脑

获取 PSSessionConfiguration (Microsoft.PowerShell.Core)


获取 PSSessionConfiguration

模块 :Microsoft.PowerShell.Core

获取计算机上注册的会话配置。

句法

Get-PSSessionConfiguration
   [[-Name] <String[]>]
   [-Force]
   [<CommonParameters>]

描述

Get-PSSessionConfiguration cmdlet 获取已在本地计算机上注册的会话配置。这是一个高级 cmdlet,旨在供系统管理员用来管理其用户的自定义会话配置。

从 PowerShell 3.0 开始,您可以使用会话配置 (.pssc) 文件定义会话配置的属性。此功能使您可以创建自定义和受限的会话,而无需编写计算机程序。有关会话配置文件的更多信息,请参阅 about_Session_Configuration_Files。

此外,从 PowerShell 3.0 开始,新的注释属性已添加到 Get-PSSessionConfiguration 返回的会话配置对象中。这些属性使用户和会话配置作者可以更轻松地检查和比较会话配置。

要创建和注册会话配置,请使用 Register-PSSessionConfiguration cmdlet。有关会话配置的更多信息,请参阅 about_Session_Configurations。

示例

示例 1 - 获取本地计算机上的会话配置

Get-PSSessionConfiguration

示例 2 - 获取两个默认会话配置

该命令使用 Get-PSSessionConfigurationName 参数仅获取名称以“Microsoft”开头的会话配置。

Get-PSSessionConfiguration -Name Microsoft*

Name                      PSVersion  StartupScript        Permission
----                      ---------  -------------        ----------
microsoft.powershell      5.1                             BUILTIN\Administrators AccessAll...
microsoft.powershell32    5.1                             BUILTIN\Administrators AccessAll...

示例 3 - 获取会话配置的属性和值

此示例显示使用会话配置文件创建的会话配置的属性和属性值。

Get-PSSessionConfiguration -Name Full  | Format-List -Property *

Copyright                     : (c) 2011 User01. All rights reserved.
AliasDefinitions              : {System.Collections.Hashtable}
SessionType                   : Default
CompanyName                   : Unknown
GUID                          : 1e9cb265-dae0-4bd3-89a9-8338a47698a1
Author                        : User01
ExecutionPolicy               : Restricted
SchemaVersion                 : 1.0.0.0
LanguageMode                  : FullLanguage
Architecture                  : 64
Filename                      : %windir%\system32\pwrshplugin.dll
ResourceUri                   : http://schemas.microsoft.com/powershell/Full
MaxConcurrentCommandsPerShell : 1500
UseSharedProcess              : false
ProcessIdleTimeoutSec         : 0
xmlns                         : http://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
MaxConcurrentUsers            : 10
lang                          : en-US
SupportsOptions               : true
ExactMatch                    : true
configfilepath                : C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\Full_1e9cb265-dae0-4bd3-89a9-8338a47698a1.pssc
RunAsUser                     :
IdleTimeoutms                 : 7200000
PSVersion                     : 3.0
OutputBufferingMode           : Block
AutoRestart                   : false
MaxShells                     : 300
MaxMemoryPerShellMB           : 1024
MaxIdleTimeoutms              : 43200000
SDKVersion                    : 1
Name                          : Full
XmlRenderingType              : text
Capability                    : {Shell}
RunAsPassword                 :
MaxProcessesPerShell          : 25
Enabled                       : True
MaxShellsPerUser              : 30
Permission                    :

该示例使用 Get-PSSessionConfiguration cmdlet 获取完整的会话配置。管道操作员将完整会话配置发送到Format-List cmdlet。值为 * (all) 的 Property 参数指示 Format-List 在列表中显示对象的所有属性和值。

输出包括有用的信息,包括会话配置的作者、会话类型、语言模式和使用此会话配置创建的会话的执行策略、会话配额以及会话配置文件的完整路径。

此会话配置视图用于包含会话配置文件的会话。有关会话配置文件的更多信息,请参阅 about_Session_Configuration_Files。

示例 4 - 查看会话配置的另一种方法

此示例使用 WSMan: 提供程序驱动器中的 Get-ChildItem cmdlet(别名 dir)来查看 Plugin 节点的内容。这是查看计算机上会话配置的另一种方法。

dir wsman:\localhost\plugin

Type            Keys                                Name
----            ----                                ----
Container       {Name=Event Forwarding Plugin}      Event Forwarding Plugin
Container       {Name=Full}                         Full
Container       {Name=microsoft.powershell}         microsoft.powershell
Container       {Name=microsoft.powershell.workf... microsoft.powershell.workflow
Container       {Name=microsoft.powershell32}       microsoft.powershell32
Container       {Name=microsoft.ServerManager}      microsoft.ServerManager
Container       {Name=WMI Provider}                 WMI Provider

PlugIn 节点包含表示注册的 PowerShell 会话配置的 ContainerElement 对象 (Microsoft.WSMan.Management.WSManConfigContainerElement) 以及 WS-Management 的其他插件。

示例 6 - 查看远程计算机上的会话配置

此示例演示如何使用 WSMan 提供程序查看远程计算机上的会话配置。此方法提供的信息不如 Get-PSSessionConfiguration 命令那么多,但用户无需成为管理员组的成员即可运行此 cmdlet。

Connect-WSMan -ComputerName Server01
dir WSMan:\Server01\Plugin

WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin

Type            Keys                                Name
----            ----                                ----
Container       {Name=Empty}                        Empty
Container       {Name=Event Forwarding Plugin}      Event Forwarding Plugin
Container       {Name=Full}                         Full
Container       {Name=microsoft.powershell}         microsoft.powershell
Container       {Name=microsoft.powershell.workf... microsoft.powershell.workflow
Container       {Name=microsoft.powershell32}       microsoft.powershell32
Container       {Name=microsoft.ServerManager}      microsoft.ServerManager
Container       {Name=NoLanguage}                   NoLanguage
Container       {Name=RestrictedLang}               RestrictedLang
Container       {Name=RRS}                          RRS
Container       {Name=SEL Plugin}                   SEL Plugin
Container       {Name=WithProfile}                  WithProfile
Container       {Name=WMI Provider}                 WMI Provider

Connect-WSMan cmdlet 连接到 Server01 远程计算机上的 WinRM 服务。 WSMan: 驱动器的 Get-ChildItem cmdlet(别名 dir)获取 Server01\Plugin 路径中的项目。输出显示 Server01 计算机上的 Plugin 目录中的项目。这些项目包括会话配置(一种 WSMan 插件)以及计算机上的其他类型的插件。

示例 7 - 从远程计算机获取详细的会话配置

此示例演示如何在远程计算机上运行 Get-PSSessionConfiguration 命令。该命令要求在本地计算机上的客户端设置和远程计算机上的服务设置中启用 CredSSP 委派。

要运行此示例中的命令,您必须是本地和远程计算机上管理员组的成员,并且必须使用以管理员身份运行选项启动 PowerShell。

Enable-WSManCredSSP -Delegate Server02
Connect-WSMan Server02
Set-Item WSMan:\Server02*\Service\Auth\CredSSP -Value $true
Invoke-Command -ScriptBlock {Get-PSSessionConfiguration} -ComputerName Server02 -Authentication CredSSP -Credential Domain01\Admin01

Name                      PSVersion  StartupScript        Permission                          PSComputerName
----                      ---------  -------------        ----------                          --------------
microsoft.powershell      5.1                             BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com
microsoft.powershell32    5.1                             BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com
MyX86Shell                5.1        c:\test\x86Shell.ps1 BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com

Enable-WSManCredSSP cmdlet 在本地计算机 Server01 上启用 CredSSP 委派。 Connect-WSMan cmdlet 连接到 Server02 计算机。此操作将 Server02 的节点添加到本地计算机上的 WSMan: 驱动器,从而允许您查看和更改 Server02 计算机上的 WS-Management 设置。 Set-Item cmdlet 将 Server02 计算机的服务节点中的 CredSSP 项的值更改为 True。这将配置远程计算机上的服务设置。 Invoke-Command cmdlet 在 Server02 计算机上运行 Get-PSSessionConfiguration 命令。该命令使用 Credential 参数,并使用值为 CredSSPAuthentication 参数。输出显示 Server02 远程计算机上的会话配置。

示例 8 - 获取会话配置的资源 URI

此示例对于设置 $PSSessionConfigurationName 首选项变量的值非常有用,该变量采用资源 URI。

(Get-PSSessionConfiguration -Name CustomShell).resourceURI

http://schemas.microsoft.com/powershell/microsoft.CustomShell

$PSSessionConfigurationName 变量指定创建会话时使用的默认配置。此变量在本地计算机上设置,但它指定远程计算机上的配置。有关 $PSSessionConfiguration 变量的详细信息,请参阅 about_Preference_Variables。

参数

-Force

如果 WinRM 服务尚未运行,则禁止提示重新启动该服务。

类型 :

SwitchParameter

位置:

命名

默认值:

None

必需的:

False

接受管道输入:

False

接受通配符:

False

-Name

仅获取具有指定名称或名称模式的会话配置。输入一个或多个会话配置名称。允许使用通配符。

类型 :

String[]

位置:

0

默认值:

本地计算机上的所有会话配置

必需的:

False

接受管道输入:

False

接受通配符:

True

输入

您无法将对象通过管道传输到此 cmdlet。

输出

Microsoft.PowerShell.Commands.PSSessionConfigurationCommands

笔记

  • 要运行此 cmdlet,请使用以管理员身份运行选项启动 PowerShell。

  • 要查看计算机上的会话配置,您必须是计算机上管理员组的成员。

  • 要在远程计算机上运行 Get-PSSessionConfiguration 命令,必须在本地计算机上的客户端设置中启用凭据安全服务提供程序 (CredSSP) 身份验证(通过使用 Enable-WSManCredSSP cmdlet)并在远程计算机上的服务设置中。此外,在建立远程会话时,您必须使用 Authentication 参数的 CredSSP 值。否则,访问将被拒绝。

  • 仅当 Get-PSSessionConfiguration 返回的对象的注释属性具有值时,它们才会出现在对象上。只有使用会话配置文件创建的会话配置才具有所有定义的属性。

  • 会话配置对象的属性随会话配置的选项设置以及这些选项的值而变化。此外,使用会话配置文件的会话配置还具有其他属性。

  • 您可以使用 WSMan: 驱动器中的命令来更改会话配置的属性。但是,您无法使用 PowerShell 2.0 中的 WSMan: 驱动器来更改 PowerShell 3.0 中引入的会话配置属性,例如 OutputBufferingMode。 PowerShell 2.0 命令不会生成错误,但它们无效。要更改 PowerShell 3.0 中引入的属性,请使用 PowerShell 3.0 中的 WSMan: 驱动器。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯