Get-PSSessionConfiguration

取得電腦上的已註冊會話組態。

Syntax

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

Description

Cmdlet Get-PSSessionConfiguration 會取得已在本機計算機上註冊的會話設定。 這是一個進階 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-PSSessionConfiguration Name 參數,只取得開頭為 「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: 提供者磁碟驅動器中的 Cmdlet (alias dir) 來查看外掛程式節點的內容。 這是查看電腦上的會話設定的另一種方式。

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,但使用者不需要是 管理員 istrators 群組的成員,即可執行此 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

Cmdlet Connect-WSMan 會連線到 Server01 遠端電腦上的 WinRM 服務。 Get-ChildItem WSMan: 磁碟驅動器的 Cmdlet (aliasdir) 會取得 Server01\Plugin 路徑中的專案。 輸出會顯示 Server01 電腦上的 Plugin 目錄中的專案。 這些專案包括會話元件,這是 WSMan 外掛程式的類型,以及電腦上的其他類型的外掛程式。

範例 7 - 從遠端電腦取得詳細的工作階段設定

此範例示範如何在遠端電腦上執行 Get-PSSessionConfiguration 命令。 命令要求在本機計算機的用戶端設定和遠端電腦上的服務設定中啟用 CredSSP 委派。

若要執行此範例中的命令,您必須是本機和遠端計算機上 管理員 istrators 群組的成員,而且您必須使用 [以系統管理員身分執行] 選項啟動 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

Cmdlet Enable-WSManCredSSP 會在 Server01 本機電腦上啟用 CredSSP 委派。 Cmdlet Connect-WSMan 會連線到 Server02 計算機。 此動作會將 Server02 的節點新增至本機電腦上的 WSMan:磁碟驅動器,讓您檢視及變更 Server02 電腦上的 WS-Management 設定。 Cmdlet 會將 Set-Item Server02 計算機服務節點中 CredSSP 專案的值變更為 True。 這會設定遠端電腦上的服務設定。 Cmdlet 會在 Invoke-Command Server02 電腦上執行Get-PSSessionConfiguration 命令。 此命令會使用 Credential 參數,並使用 Authentication 參數搭配 CredSSP 的值。 輸出會顯示 Server02 遠端電腦上的工作階段設定。

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

此範例適用於設定採用資源 URI 之 $PSSessionConfigurationName 喜好設定變數的值。

(Get-PSSessionConfiguration -Name CustomShell).resourceURI

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

變數 $PSSessionConfigurationName 會指定建立工作階段時所使用的預設組態。 此變數是在本機計算機上設定,但它會指定遠端電腦上的組態。 如需變數的詳細資訊 $PSSessionConfiguration ,請參閱 about_Preference_Variables

參數

-Force

如果服務尚未執行,則隱藏重新啟動WinRM服務的提示。

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

只取得具有指定名稱或名稱模式的工作階段組態。 輸入一或多個工作階段組態名稱。 允許通配符。

Type:String[]
Position:0
Default value:All session configurations on the local computer
Required:False
Accept pipeline input:False
Accept wildcard characters:True

輸入

None

您無法使用管線將物件傳送至此 Cmdlet。

輸出

Microsoft.PowerShell.Commands.PSSessionConfigurationCommands

備註

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

  • 若要檢視電腦上的會話設定,您必須是計算機上 管理員 istrators 群組的成員。

  • 若要在遠端電腦上執行 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: 磁碟驅動器。