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:測試會話組態的會話組態檔

在此範例中,我們會測試限制會話組態中使用的組態檔。 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 屬性值(prints)。 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

輸入

String

您可以使用管線將會話組態檔路徑傳送至此 Cmdlet。

輸出

Boolean

備註

此 Cmdlet 僅適用於 Windows 平臺。