Test-PSSessionConfigurationFile
驗證會話組態檔中的索引鍵和值。
語法
Test-PSSessionConfigurationFile
[-Path] <String>
[<CommonParameters>]
Description
此 Cmdlet 只能在 Windows 平臺上使用。
此 Cmdlet 會驗證會話組態檔是否包含有效的索引鍵,且值是正確的類型。 針對列舉值,Cmdlet 會驗證指定的值是否有效。
Cmdlet 傳回 $True
代表檔案通過所有測試;若未通過,則傳回 $False
。 若要尋找任何錯誤,請使用 Verbose 參數。
Test-PSSessionConfigurationFile
會驗證會話組態檔,例如 New-PSSessionConfigurationFile
Cmdlet 所建立的組態檔。 如需工作階段組態的相關信息,請參閱 about_Session_Configurations。 如需工作階段組態檔的相關資訊,請參閱 about_Session_Configuration_Files。
此 Cmdlet 已在 PowerShell 3.0 中引進。
範例
範例 1:測試會話組態檔
Test-PSSessionConfigurationFile -Path "FullLanguage.pssc"
True
範例 2:測試會話組態的會話組態檔
在此範例中,我們會測試 受限制 會話組態中使用的組態檔。
Path 參數的值是執行 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 屬性的值已填入(為真),則命令會取得(顯示)ConfigFilePath 屬性的值。 然後使用 Test-PSSessionConfigurationFile
Cmdlet 來測試 ConfigFilePath 值中的檔案。
Verbose 參數會在檔案失敗測試時傳回檔案錯誤。
參數
-Path
指定工作階段組態檔的路徑和檔名(.pssc)。 如果您省略路徑,預設值為目前的資料夾。 支援通配符,但必須解析成單一檔案。 您也可以透過管道將會話組態檔路徑傳送至 Test-PSSessionConfigurationFile
。
類型: | String |
Position: | 0 |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | True |
輸入
您可以將會話組態檔路徑以管道傳送至此 cmdlet。
輸出
備註
此 Cmdlet 僅適用於 Windows 平臺。
相關連結
- Disable-PSSessionConfiguration
- Enable-PSSessionConfiguration
- Get-PSSessionConfiguration
- New-PSSessionConfigurationFile
- New-PSSessionOption
- Register-PSSessionConfiguration
- Set-PSSessionConfiguration
- Test-PSSessionConfigurationFile
- Unregister-PSSessionConfiguration
- WSMan 提供者
- about_Session_Configurations
- 關於 Session Configuration Files (會話配置檔案)