From 4cc760e94deee0b263d5e4d628c5ed03e68620e5 Mon Sep 17 00:00:00 2001 From: Paul Broadwith Date: Fri, 16 Jul 2021 03:30:11 +0100 Subject: [PATCH] (#146) Check state after install / upgrade --- .../cChocoPackageInstall/cChocoPackageInstall.psm1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 index 539845a..9ad604f 100644 --- a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 +++ b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 @@ -139,6 +139,20 @@ function Set-TargetResource InstallPackage -pName $Name -pParams $Params -pVersion $versionToInstall -pSource $Source -cParams $chocoParams } } + + # check state of package + $isInstalled = IsPackageInstalled -pName $Name + + if ($Ensure -eq 'Absent') { + if ($isInstalled -eq $true) { + throw "Failed to uninstall Chocolatey package '$Name'." + } + } + else { + if ($isInstalled -eq $false) { + throw "Failed to install Chocolatey package '$Name'." + } + } } function Test-TargetResource