共用方式為


Test-DscConfiguration

測試節點上的實際組態是否符合所需的組態。

語法

Test-DscConfiguration
    [[-ComputerName] <String[]>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-AsJob]
    [-Detailed]
    [<CommonParameters>]
Test-DscConfiguration
    [[-ComputerName] <String[]>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-AsJob]
    [-Path] <String>
    [<CommonParameters>]
Test-DscConfiguration
    [[-ComputerName] <String[]>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-AsJob]
    -ReferenceConfiguration <String>
    [<CommonParameters>]
Test-DscConfiguration
    [-ThrottleLimit <Int32>]
    -CimSession <CimSession[]>
    [-AsJob]
    [-Path] <String>
    [<CommonParameters>]
Test-DscConfiguration
    [-ThrottleLimit <Int32>]
    -CimSession <CimSession[]>
    [-AsJob]
    -ReferenceConfiguration <String>
    [<CommonParameters>]
Test-DscConfiguration
    [-ThrottleLimit <Int32>]
    -CimSession <CimSession[]>
    [-AsJob]
    [-Detailed]
    [<CommonParameters>]

Description

Test-DscConfiguration Cmdlet 會測試節點上的實際組態是否符合所需的組態。 使用計算機名稱或 Common Information Model (CIM) 工作階段,指定要測試設定的電腦。 如果您未指定目標計算機,Cmdlet 會測試本機電腦的組態。

如果所需的和實際組態相符,Cmdlet 會傳回 'True' 的字串值。 否則,它會傳回 『False』 的字串值。

範例

範例 1:測試本機計算機的組態

Test-DscConfiguration

此命令會測試本機計算機的組態。

範例 2:測試指定計算機的組態

$Session = New-CimSession -ComputerName "Server01" -Credential ACCOUNTS\PattiFuller
Test-DscConfiguration -CimSession $Session

此範例會從 CIM 會話指定的計算機測試組態。 此範例會為名為 Server01 的電腦建立 CIM 會話,以搭配 Cmdlet 使用。 或者,建立 CIM 會話陣列,以將 Cmdlet 套用至多個指定的電腦。

第一個命令會使用 New-CimSession Cmdlet 建立 CIM 會話,然後將 CimSession 物件儲存在 $Session 變數中。 命令會提示您輸入密碼。 如需詳細資訊,請輸入 Get-Help New-CimSession

第二個命令會測試 CimSession 所識別之計算機的組態, 儲存在 $Session 變數中的物件,在此案例中為名為 Server01 的計算機。

範例 3:使用詳細結果測試組態

Test-DscConfiguration -ComputerName "Server01", "Server02", "Server03" -Detailed

此命令會測試 ComputerName 參數所指定之一組計算機的組態,並傳回包含整體狀態、處於所需狀態的資源、不符合所需狀態的資源和計算機名稱的詳細資訊。

範例 4:測試資料夾中指定的組態

Test-DscConfiguration -Path "C:\Dsc\Configurations"

此命令會測試 Path 參數所指定資料夾中定義的組態。 這些組態會針對一組計算機進行測試,每個計算機都是由組態檔的檔名所識別。

範例 5:測試檔案中指定的組態

Test-DscConfiguration -ReferenceConfiguration "C:\Dsc\Configurations\WebServer.mof" -ComputerName "Server01", "Server02", "Server03"

此命令會針對 ComputerName 參數所指定的一組計算機,測試檔案中定義的組態。

參數

-AsJob

表示此 Cmdlet 會以背景工作的形式執行命令。

如果您指定 AsJob 參數,命令會傳回代表作業的物件,然後顯示命令提示字元。 您可以繼續在會話中工作,直到作業完成為止。 作業會在本機計算機上建立,而遠端計算機的結果會自動傳回至本機計算機。 若要管理作業,請使用作業 Cmdlet。 若要取得作業結果,請使用 Receive-Job Cmdlet。

若要使用此參數,本機和遠端計算機必須設定為遠端,而且在 Windows Vista 和更新版本的 Windows作系統上,您必須使用 [以系統管理員身分執行] 選項開啟 Windows PowerShell。 如需詳細資訊,請參閱 about_Remote_Requirements

如需 Windows PowerShell 背景工作的詳細資訊,請參閱 about_Jobsabout_Remote_Jobs

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-CimSession

在遠端會話或遠端電腦上執行 Cmdlet。 輸入計算機名稱或會話物件,例如 New-CimSessionGet-CimSession Cmdlet 的輸出。 預設為本機電腦上的目前會話。

類型:CimSession[]
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-ComputerName

指定此 Cmdlet 測試設定的電腦名稱陣列。 Cmdlet 會測試這些電腦 Path 參數所指定位置中的組態檔。

類型:String[]
別名:CN, ServerName
Position:1
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-Credential

指定目標計算機的使用者名稱和密碼,做為 PSCredential 物件。 若要取得 PSCredential 物件,請使用 Get-Credential Cmdlet。 如需詳細資訊,請輸入 Get-Help Get-Credential

類型:PSCredential
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Detailed

指出此 Cmdlet 會傳回比較組態檔與節點所需狀態的詳細結果。 結果包含資訊,例如整體狀態、處於預期狀態的資源、不符合預期狀態的資源,以及計算機名稱。

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Path

指定包含組態檔檔的資料夾路徑。 Cmdlet 會根據 ComputerNameCimSession 參數所指定的計算機狀態來測試組態。

類型:String
Position:0
預設值:None
必要:True
接受管線輸入:False
接受萬用字元:False

-ReferenceConfiguration

指定組態檔檔的路徑。 此 Cmdlet 會根據 ComputerNameCimSession 參數所指定之電腦的實際狀態來測試組態。

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:False
接受萬用字元:False

-ThrottleLimit

指定可以建立以執行 Cmdlet 的並行作業數目上限。 如果省略此參數或輸入 0 的值,則 Windows PowerShell 會根據計算機上執行的 CIM Cmdlet 數目,計算 Cmdlet 的最佳節流限制。 節流限制僅適用於目前的 Cmdlet,不適用於工作階段或電腦。

類型:Int32
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False