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。 屬性參數,其值為 *
(所有) 會指示 Format-List
在清單中顯示物件的所有屬性和值。
輸出包含有用的資訊,包括會話設定的作者、會話類型、語言模式,以及使用此會話組態、會話配額和會話組態檔的完整路徑所建立的會話執行原則。
此工作階段設定的檢視可用於包含工作階段設定檔的工作階段。 如需有關工作階段設定檔的詳細資訊,請參閱 about_Session_Configuration_Files。
範例 4 - 查看會話設定的另一種方式
此範例會 Get-ChildItem
使用 WSMan: 提供者磁片磁碟機中的 Cmdlet (別名 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。代表已註冊 PowerShell 會話設定的 WSMan.Management.WSManConfigContainerElement) ,以及其他 WS-Management 外掛程式。
範例 6 - 檢視遠端電腦上的會話設定
此範例示範如何使用 WSMan 提供者檢視遠端電腦上的工作階段設定。 這個方法不會提供與命令相同的資訊 Get-PSSessionConfiguration
,但使用者不需要是 Administrators 群組的成員才能執行此 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 服務。 Cmdlet Get-ChildItem
(WSMan: 磁片磁碟機的別名 dir
) 會取得 Server01\Plugin 路徑中的專案。 輸出會顯示 Server01 電腦上 Plugin 目錄中的項目。 此項目包含工作階段設定 (一種 WSMan 外掛程式) 及電腦上其他類型的外掛程式。
範例 7 - 從遠端電腦取得詳細的會話設定
此範例示範如何在遠端電腦上執行 Get-PSSessionConfiguration
命令。 此命令會要求在本機電腦上的用戶端設定及遠端電腦上的服務設定中啟用 CredSSP 委派。
若要執行此範例中的命令,您必須是本機和遠端電腦上的 Administrators 群組成員,而且您必須使用 [ 以系統管理員身分執行 ] 選項啟動 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
Get-PSSessionConfiguration
Server02 電腦上執行 命令。 此命令使用 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 服務的提示。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Name
只取得具有指定名稱或名稱模式的工作階段設定。 輸入一或多個工作階段設定名稱。 允許使用萬用字元。
Type: | String[] |
Position: | 0 |
Default value: | All session configurations on the local computer |
Accept pipeline input: | False |
Accept wildcard characters: | True |
輸入
None
您無法使用管線將物件傳送至此 Cmdlet。
輸出
Microsoft.PowerShell.Commands.PSSessionConfigurationCommands
備註
若要執行此 Cmdlet,請使用 [ 以系統管理員身分執行 ] 選項啟動 PowerShell。
若要檢視電腦上的工作階段設定,您必須是電腦上 Administrators 群組的成員。
若要在遠端電腦上執行
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: 磁片磁碟機。
相關連結
- Disable-PSSessionConfiguration
- Enable-PSSessionConfiguration
- Get-PSSessionConfiguration
- New-PSSessionConfigurationFile
- New-PSSessionOption
- Register-PSSessionConfiguration
- Set-PSSessionConfiguration
- Test-PSSessionConfigurationFile
- Unregister-PSSessionConfiguration
- WSMan 提供者
- about_Session_Configurations
- about_Session_Configuration_Files
意見反應
提交並檢視相關的意見反應