共用方式為


DSC WindowsPackageCab 資源

適用於:Windows PowerShell 5.1

Windows PowerShell 預期狀態設定 (DSC) 中的 WindowsPackageCab 資源提供一個機制,可在目標節點上安裝或解除安裝 Windows 封包 (.cab) 套件。

目標節點上必須安裝 DISM PowerShell 模組。 如需相關資訊,請參閱在 Windows PowerShell 中使用 DISM

注意

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

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

語法

{
    Name = [string]
    SourcePath = [string]
    [ LogPath = [string] ]
    [ DependsOn = [string[]] ]
    Ensure = [string] { Absent | Present }
    [ PsDscRunAsCredential = [PSCredential] ]
}

屬性

屬性 描述
名稱 指出您想要確保其特定狀態的套件名稱。
SourcePath 指出套件所在的檔案路徑
LogPath 指出您想要提供者儲存記錄檔來安裝或解除安裝此套件的完整路徑。

通用屬性

屬性 描述
DependsOn 表示必須先執行另一個資源的設定,再設定這個資源。 例如,如果第一個想要執行的資源設定指令碼區塊識別碼是 ResourceName,而其類型是 ResourceType,則使用這個屬性的語法就是 DependsOn = "[ResourceType]ResourceName"
Ensure 指出是否要安裝此套件。 將此屬性設定為 Absent ,以確保套件未安裝 (,或在安裝套件時卸載套件) 。 將其設定為 Present 以確保已安裝此套件。 EnsureWindowsPackageCab 資源上的必要屬性。
PsDscRunAsCredential 設定用於執行整個資源的認證。

範例

以下範例設定會接受輸入參數,並確保安裝 $Name 參數所指定的 .cab 檔案。

Configuration Sample_WindowsPackageCab
{
    param
    (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Name,

        [Parameter (Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $SourcePath,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $LogPath
    )

    Import-DscResource -ModuleName 'PSDscResources'

    WindowsPackageCab WindowsPackageCab1
    {
        Name = $Name
        Ensure = 'Present'
        SourcePath = $SourcePath
        LogPath = $LogPath
    }
}