Get-PSSessionConfiguration

取得電腦上註冊的會話設定。

語法

Default (預設值)

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

Description

指令 Get-PSSessionConfiguration 檔會取得已在本地電腦註冊的會話設定。 這是一個進階指令小程式,設計給系統管理員用來管理使用者自訂的會話設定。

從 PowerShell 3.0 開始,你可以透過使用 session configuration(.pssc) 檔案來定義會話組態的屬性。 此功能讓您能在不撰寫程式的情況下,建立客製化且受限的會話。 如需工作階段組態檔的詳細資訊,請參閱 about_Session_Configuration_Files。

此外,從 PowerShell 3.0 開始,回傳的會話設定物件 Get-PSSessionConfiguration 新增了筆記屬性。 這些屬性讓使用者與會話設定作者更容易檢視與比較會話組態。

要建立並註冊會話設定,請使用 Register-PSSessionConfiguration cmdlet。 如需工作階段組態的詳細資訊,請參閱 about_Session_Configurations。

範例

範例 1 - 在本地電腦取得會話設定

Get-PSSessionConfiguration

範例 2 - 取得兩個預設的會話設定

指令使用 Name 參數 Get-PSSessionConfiguration,只取得名稱以「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。 Property 參數的*值為 (all) 時,指示Format-List在清單中顯示物件的所有屬性與值。

輸出包含有用資訊,包括會話設定的作者、會話類型、語言模式,以及使用此會話設定建立的會話執行政策、會話配額,以及會話設定檔的完整路徑。

此會話設定視圖用於包含會話設定檔的會話。 如需工作階段組態檔的詳細資訊,請參閱 about_Session_Configuration_Files。

範例 4 - 另一種看待會話配置的方式

此範例使用 Get-ChildItem WSMan: provider 磁碟中的 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節點包含 ContainerElement物件(Microsoft。WSMan.Management.WSManConfigContainerElement)代表註冊的 PowerShell 會話設定,以及其他 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 指令長可連接 Server01 遠端電腦上的 WinRM 服務。 Get-ChildItem WSMan: 磁碟機的 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 指令檔能在本地電腦 Server01 上啟用 CredSSP 委派。 該 Connect-WSMan 指令檔連接至 Server02 電腦。 此動作會在本地電腦的 WSMan: 磁碟機中新增 Server02 節點,讓您能查看並更改 Server02 電腦上的 WS-Management 設定。 該 Set-Item cmdlet 會將 Server02 電腦服務節點中 CredSSP 項目的值改為 True。 這會設定遠端電腦的服務設定。 Invoke-Command指令檔會在 Server02 電腦上執行此Get-PSSessionConfiguration指令。 指令使用 Credential 參數,並使用 Authentication 參數,值為 CredSSP。 輸出顯示 Server02 遠端電腦的會話配置。

範例 8 - 取得會話設定的資源 URI

此範例對於設定偏好變數的 $PSSessionConfigurationName 值非常有用,該變數會使用資源 URI。

(Get-PSSessionConfiguration -Name CustomShell).ResourceUri
http://schemas.microsoft.com/powershell/microsoft.CustomShell

變 $PSSessionConfigurationName 數指定建立會話時使用的預設設定。 此變數設定在本地電腦上,但指定遠端電腦的設定。 如需 $PSSessionConfiguration 變數的詳細資訊,請參閱 about_Preference_Variables。

參數

-Force

如果 WinRM 服務尚未執行,會抑制重新啟動 WinRM 服務的提示。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Name

僅取得指定名稱或名稱模式的會話配置。 輸入一個或多個會話設定名稱。 允許使用通配符。

參數屬性

類型:

String[]

預設值:All session configurations on the local computer
支援萬用字元:True
不要顯示:False

參數集

(All)
Position:0
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

CommonParameters

此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。

輸入

None

您不能將物件透過管道傳送到此 Cmdlet。

輸出

Microsoft.PowerShell.Commands.PSSessionConfigurationCommands

備註

  • 若要執行此 Cmdlet,請以 [以系統管理員身分執行] 選項啟動 PowerShell。

  • 要查看電腦上的會話設定,您必須是該電腦管理員群組的成員。

  • 若要在遠端電腦執行 Get-PSSessionConfiguration 指令,必須在本地電腦的用戶端設定中啟用憑證安全服務提供者(CredSSP)認證(透過 cmdlet Enable-WSManCredSSP ),以及遠端電腦的服務設定中啟用。 此外,建立遠端會話時,你必須使用 Authentication 參數的 CredSSP 值。 否則,存取將被拒絕。

  • 回 Get-PSSessionConfiguration 傳物件的筆記屬性只有在物件有值時才會出現。 只有使用會話設定檔建立的會話設定才具備所有定義的屬性。

  • 會話組態對象的屬性會隨著會話組態和這些選項的值所設定的選項而有所不同。 此外,使用會話組態檔的會話組態也有其他屬性。

  • 你可以在 WSMan: drive 中使用指令來更改會話設定的屬性。 然而,你不能使用 PowerShell 2.0 中的 WSMan: 磁碟機來更改 PowerShell 3.0 中引入的會話設定屬性,例如 OutputBufferingMode。 PowerShell 2.0 指令不會產生錯誤,但它們是無效的。 若要更改 PowerShell 3.0 中引入的屬性,請使用 PowerShell 3.0 中的 WSMan: 磁碟。