Test-PSSessionConfigurationFile

驗證會話設定檔中的鍵與值。

語法

Default (預設值)

Test-PSSessionConfigurationFile
    [-Path] <String>
    [<CommonParameters>]

Description

此 Cmdlet 只能在 Windows 平臺上使用。

此 cmdlet 用以驗證會話設定檔是否包含有效的金鑰,且值類型正確。 對於列舉值,指令集會驗證指定的值是否有效。

如果檔案通過所有測試$false,則返回$true指令長,若未通過。 要找出任何錯誤,請使用 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 屬性的值被填入(為 true),指令就會取得(列印) ConfigFilePath 屬性值。 接著它會用 Test-PSSessionConfigurationFile cmdlet 測試 ConfigFilePath 值中的檔案。 Verbose 參數會在檔案測試失敗時回傳檔案錯誤。

參數

-Path

指定會話設定檔(.pssc)的路徑與檔名。 如果你省略路徑,預設就是目前的資料夾。 支援通行符,但必須解析為單一檔案。 你也可以將會話設定檔路徑導向 Test-PSSessionConfigurationFile。

參數屬性

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

參數集

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

CommonParameters

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

輸入

String

你可以將一個會話設定檔路徑導向這個 cmdlet。

輸出

Boolean

備註

此 Cmdlet 僅適用於 Windows 平臺。