Test-PSSessionConfigurationFile
驗證工作階段設定檔中的索引鍵和值。
Syntax
Test-PSSessionConfigurationFile
[-Path] <String>
[<CommonParameters>]
Description
此 Cmdlet 僅適用于 Windows 平臺。
此 Cmdlet 會驗證會話組態檔是否包含有效的金鑰,且這些值的類型正確。 對於列舉的值,此 Cmdlet 會驗證指定的值是否有效。
如果檔案通過所有測試,而且 $False
沒有,則 Cmdlet 會傳回 $True
。 若要尋找任何錯誤,請使用 Verbose 參數。
Test-PSSessionConfigurationFile
驗證會話組態檔,例如 Cmdlet 所建立的 New-PSSessionConfigurationFile
組態檔。 如需會話設定的相關資訊,請參閱 about_Session_Configurations。 如需會話組態檔的相關資訊,請參閱 about_Session_Configuration_Files。
此 Cmdlet 是在 PowerShell 3.0 中引進。
範例
範例 1:測試工作階段設定檔
Test-PSSessionConfigurationFile -Path "FullLanguage.pssc"
True
範例 2:測試工作階段設定的工作階段設定檔
在此範例中,我們會測試 Restricted 會話組態中使用的組態檔。
Path參數的值是取得Restricted會話組態之命令的結果 Get-PSSessionConfiguration
。 工作階段設定檔的路徑儲存在工作階段設定之 ConfigFilePath 屬性的值中。
Test-PSSessionConfigurationFile -Path (Get-PSSessionConfiguration -Name Restricted).ConfigFilePath
範例 3:測試所有工作階段設定檔
此範例中的 函式會測試本機電腦上的所有會話組態檔。 函式會 Get-PSSessionConfiguration
使用 Cmdlet 來取得所有會話設定。 迴圈內的 ForEach-Object
程式碼會顯示檔案路徑,並測試每個會話組態。
function Test-AllConfigFiles
{
Get-PSSessionConfiguration | ForEach-Object {
if ($_.ConfigFilePath) {
$_.ConfigFilePath
Test-PSSessionConfigurationFile -Verbose -Path $_.ConfigFilePath
}
}
}
Test-AllConfigFiles
C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\Empty_6fd77bf6-e084-4372-bd8a-af3e207354d3.pssc
True
C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\Full_1e9cb265-dae0-4bd3-89a9-8338a47698a1.pssc
VERBOSE: The member 'AliasDefinitions' must contain the required key 'Description'. Add the require key
to the fileC:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\Full_1e9cb265-dae0-4bd3-89a9-8338a47698a1.pssc.
False
C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\NoLanguage_0c115179-ff2a-4f66-a5eb-e56e5692ba22.pssc
True
C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\RestrictedLang_b6bd9474-0a6c-4e06-8722-c2c95bb10d3e.pssc
True
C:\WINDOWS\System32\WindowsPowerShell\v1.0\SessionConfig\RRS_3fb29420-2c87-46e5-a402-e21436331efc.pssc
True
工作階段設定的 ConfigFilePath 屬性包含在工作階段設定中使用之工作階段設定檔的路徑 (如果有的話)。
如果已填入 ConfigFilePath 屬性的值 (為 True),此命令會取得 (印出) ConfigFilePath 屬性的值。 然後它會 Test-PSSessionConfigurationFile
使用 Cmdlet 來測試 ConfigFilePath 值中的檔案。 當檔案無法通過測試時,Verbose 參數會傳回檔案錯誤。
參數
-Path
指定會話組態檔 (.pssc) 的路徑和檔名。 若省略路徑,則預設為目前資料夾。 支援使用萬用字元,但它們必須解析為單一檔案。 您也可以使用管線將會話組態檔路徑傳送至 Test-PSSessionConfigurationFile
。
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
輸入
您可以使用管線將會話組態檔路徑傳送至 Test-PSSessionConfigurationFile
。
輸出
備註
此 Cmdlet 僅適用于 Windows 平臺。
相關連結
- 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