共用方式為


DSC WindowsOptionalFeatureSet 資源

適用於:Windows PowerShell 5.x

Windows PowerShell 預期狀態設定 (DSC) 的 WindowsOptionalFeatureSet 資源提供一個機制,確保可在目標節點上啟用選用功能。 此資源是針對Name 屬性中所指定每項功能呼叫 WindowsOptionalFeature 資源複合資源

當您想要將多個 Windows 選用功能設定成相同的狀態,請使用此資源。

注意

此 DSC 資源的本檔涵蓋 7.2 版之前 PowerShell 隨附的版本。 PSDscResources模組包含 Microsoft 正式支援的全新和更新 DSC 資源。 PSDscResources 模組可從 PowerShell 資源庫中取得。

如需詳細資訊和更新的檔,請參閱 PSDscResources 參考檔

語法

WindowsOptionalFeatureSet [string] #ResourceName
{
    Name = [string[]]
    [ RemoveFilesOnDisable = [bool] ]
    [ LogPath = [string] ]
    [ NoWindowsUpdateCheck = [bool] ]
    [ LogLevel = [string] { ErrorsOnly | ErrorsAndWarning | ErrorsAndWarningAndInformation }  ]
    [ DependsOn = [string[]] ]
    [ Ensure = [string] { Enable | Disable }  ]
    [ PsDscRunAsCredential = [PSCredential] ]
}

屬性

屬性 描述
名稱 表示您想要確保啟用或停用的功能名稱。
NoWindowsUpdateCheck 指定在搜尋來源檔案以啟用功能時,DISM 是否連絡 Windows Update (WU)。 若為 $true,則 DISM 不連絡 WU。
RemoveFilesOnDisable Ensure 設定為 Absent 時,設定為 $true 可移除與此功能建立關聯的所有檔案。
LogLevel 記錄中顯示的最大輸出等級。 接受的值為:ErrorsOnlyErrorsAndWarningErrorsAndWarningAndInformation
LogPath 要讓資源提供者記錄作業的記錄檔路徑。

通用屬性

屬性 描述
DependsOn 表示必須先執行另一個資源的設定,再設定這個資源。 例如,如果第一個想要執行的資源設定指令碼區塊識別碼是 ResourceName,而其類型是 ResourceType,則使用這個屬性的語法就是 DependsOn = "[ResourceType]ResourceName"
Ensure 指定是否啟用功能。 若要確保已啟用此功能,請將此屬性設定為 Enable。 若要確保已停用此功能,請將此屬性設定為 Disable。 預設值為 Enable
PsDscRunAsCredential 設定用於執行整個資源的認證。

注意

已在 WMF 5.0 中新增 PsDscRunAsCredential 通用屬性,以允許在其他認證的內容中執行任何 DSC 資源。 如需詳細資訊,請參閱搭配 DSC 資源使用認證