Get-PSSessionConfiguration
获取计算机上已注册的会话配置。
语法
Get-PSSessionConfiguration [[-Name] <string[]>] [<CommonParameters>]
说明
Get-PSSessionConfiguration cmdlet 获取已在本地计算机上注册的会话配置。这是一个高级 cmdlet,供系统管理员为其用户管理自定义会话配置时使用。
要创建并注册会话配置,请使用 Register-PSSessionConfiguration cmdlet。
参数
-Name <string[]>
只获取具有指定的名称或名称模式的会话配置。输入一个或多个会话配置名称。允许使用通配符。
是否为必需? |
false |
位置? |
1 |
默认值 |
本地计算机上的所有会话配置 |
是否接受管道输入? |
false |
是否接受通配符? |
true |
<CommonParameters>
此 cmdlet 支持通用参数:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。有关详细信息,请参阅 about_Commonparameters.
输入和输出
输入类型是指可通过管道传递给 cmdlet 的对象的类型。返回类型是指 Cmdlet 所返回对象的类型。
输入 |
无 不能通过管道将输入传递给此 cmdlet。 |
输出 |
Microsoft.PowerShell.Commands.PSSessionConfigurationCommands#PSSessionConfiguration |
说明
若要在 Windows Vista、Windows Server 2008 以及更高版本的 Windows 上运行此 cmdlet,您必须使用“以管理员身份运行”选项打开 Windows PowerShell。
若要查看计算机上的会话配置,您必须是该计算机上的 Administrators 组的成员。
若要在远程计算机上运行 Get-PSSessionConfiguration 命令,必须在本地计算机的客户端设置(通过使用 Enable-WSManCredSSP cmdlet)和远程计算机的服务设置中启用凭据安全服务提供程序 (CredSSP) 身份验证,还必须在建立远程会话时使用 Authentication 参数的 CredSSP 值。否则,访问将被拒绝。
示例 1
C:\PS>get-pssessionconfiguration
说明
-----------
此命令获取计算机上的会话配置。
示例 2
C:\PS>get-pssessionconfiguration -name Microsoft*
Name PSVersion StartupScript Permission
---- --------- ------------- ----------
microsoft.powershell 2.0 BUILTIN\Administrators AccessAll...
microsoft.powershell32 2.0 BUILTIN\Administrators AccessAll...
说明
-----------
此命令使用 Get-PSSessionConfiguration 的 Name 参数只获取名称以“Microsoft”开头的会话配置。
此命令获取 Windows PowerShell 附带的两个默认会话配置。
示例 3
C:\PS>Get-PSSessionConfiguration -name microsoft.powershell | get-member
TypeName: Microsoft.PowerShell.Commands.PSSessionConfigurationCommands#PSSessionConfiguration
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Capability NoteProperty System.Object[] Capability=System.Object[]
ExactMatch NoteProperty System.String ExactMatch=False
Filename NoteProperty System.String Filename=%windir%\system32\pwrshplugin.dll
lang NoteProperty System.String lang=en-US
Name NoteProperty System.String Name=microsoft.powershell
PSVersion NoteProperty System.String PSVersion=2.0
ResourceUri NoteProperty System.String ResourceUri=https://schemas.microsoft.com/powershell/microsoft.powershell
SDKVersion NoteProperty System.String SDKVersion=1
SecurityDescriptorSddl NoteProperty System.String SecurityDescriptorSddl=O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
SupportsOptions NoteProperty System.String SupportsOptions=true
Uri NoteProperty System.String Uri=https://schemas.microsoft.com/powershell/microsoft.powershell
xmlns NoteProperty System.String xmlns=https://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
XmlRenderingType NoteProperty System.String XmlRenderingType=text
Permission ScriptProperty System.Object Permission {get=trap { continue; }...
C:\PS> Get-PSSessionConfiguration -name microsoft.powershell | format-list -property *
Name : microsoft.powershell
Filename : %windir%\system32\pwrshplugin.dll
SDKVersion : 1
XmlRenderingType : text
lang : en-US
PSVersion : 2.0
ResourceUri : https://schemas.microsoft.com/powershell/microsoft.powershell
SupportsOptions : true
Capability : {Shell}
Uri : https://schemas.microsoft.com/powershell/microsoft.powershell
SecurityDescriptorSddl : O:NSG:BAD:P(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
ExactMatch : False
xmlns : https://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
Permission : BUILTIN\Administrators AccessAllowed
说明
-----------
这些命令检查 Get-PSSessionConfiguration 返回的 PSSessionConfiguration 对象。
第一条命令使用 Get-PSSessionConfiguration cmdlet 来获取 Microsoft.PowerShell 默认配置。
第二条命令使用管道运算符 (|) 将 Get-PSSessionConfiguration 返回的对象发送到 Get-Member cmdlet。输出将显示该对象的属性和方法。
第三条命令将该对象发送到 Format-List cmdlet。值为 *(全部)的 Property 参数指示 Format-List 在列表中显示该对象的所有属性和属性值。
此命令的输出包含非常有用的信息,其中包括实现配置类型的 .dll 的位置、所创建的终结点的统一资源标识符 (URI) 以及配置的安全描述符定义语言 (SDDL)。
示例 4
C:\PS>dir wsman:\localhost\plugin
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin
Name Type Keys
---- ---- ----
Event Forwarding Plugin Container {Name=Event Forwarding Plugin}
MaintenanceShell Container {Name=MaintenanceShell}
microsoft.powershell Container {Name=microsoft.powershell}
microsoft.powershell32 Container {Name=microsoft.powershell32}
WMI Provider Container {Name=WMI Provider}
说明
-----------
此命令在 WSMan: 提供程序驱动器中使用 Get-ChildItem cmdlet(别名为 dir)查看 Plugin 节点的内容。
这是在计算机上查看会话配置的另一种方式。
PlugIn 节点包含表示已注册的 Windows PowerShell 会话配置的 ContainerElement 对象 (Microsoft.WSMan.Management.WSManConfigContainerElement) 以及 WS-Management 的其他插件。
示例 5
C:\PS>enable-wsmanCredSSP -delegate server02
C:\PS> connect-wsman server02
C:\PS> set-item wsman:\server02*\service\auth\credSSP -value $true
C:\PS> invoke-command -scriptblock {Get-PSSessionConfiguration} -computername Server02 -authentication CredSSP -credential Domain01\Admin01
Name PSVersion StartupScript Permission PSComputerName
---- --------- ------------- ---------- --------------
microsoft.powershell 2.0 BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com
microsoft.powershell32 2.0 BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com
MyX86Shell 2.0 c:\test\x86Shell.ps1 BUILTIN\Administrators AccessAll... server02.corp.fabrikam.com
说明
-----------
此示例说明如何在远程计算机上运行 Get-PSSessionConfiguration 命令。该命令要求在本地计算机的客户端设置中以及远程计算机的服务设置中启用 CredSSP 委派。若要运行此示例中的命令,您必须是本地计算机和远程计算机上的 Administrators 组的成员。
第一条命令使用 Enable-WSManCredSSP cmdlet 启用从本地计算机 Server01 到远程计算机 Server02 的 CredSSP 委派。这会在本地计算机上配置 CredSSP 客户端设置。
第二条命令使用 Connect-WSMan cmdlet 连接到计算机 Server02。此操作在本地计算机上的 WSMan: 驱动器中为计算机 Server02 添加一个节点,从而允许您查看和更改计算机 Server02 上的 WS-Management 设置。
第三条命令使用 Set-Item cmdlet 将计算机 Server02 的 Service 节点中 CredSSP 项的值更改为 True。这会在远程计算机上配置服务设置。
第四条命令使用 Invoke-Command cmdlet 在计算机 Server02 上运行 Get-PSSessionConfiguration 命令。此命令使用 Credential 参数,并使用值为 CredSSP 的 Authentication 参数。
示例 6
C:\PS>(get-PSSessionConfiguration -name CustomShell).resourceURI
https://schemas.microsoft.com/powershell/microsoft.CustomShell
说明
-----------
此命令使用 Get-PSSessionConfiguration cmdlet 获取会话配置的资源 URI。
在设置接受资源 URI 的 $PSSessionConfigurationName 首选项变量的值时,该命令十分有用。
$PSSessionConfiguationName 变量指定创建会话时所用的默认配置。此变量是在本地计算机上设置的,但是它指定远程计算机上的配置。有关 $PSSessionConfiguration 变量的详细信息,请参阅 about_Preference_Variables。
另请参阅
概念
about_Session_Configurations
Disable-PSSessionConfiguration
Enable-PSSessionConfiguration
Register-PSSessionConfiguration
Set-PSSessionConfiguration
Unregister-PSSessionConfiguration
WSMan Provider