From 601e2cf50b36da64d4efcf8d92354cd97efd91c4 Mon Sep 17 00:00:00 2001 From: "Carpenter, Richard" Date: Fri, 7 Jul 2023 09:55:28 +0100 Subject: [PATCH] * Disables Verbose progress during install and upgrade (#175). Assigns $env:ChocolateyInstall from the System environment variable if $env:ChocolateyInstal is $null (#174) --- .../cChocoPackageInstall.psm1 | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 index 539845a..4b09989 100644 --- a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 +++ b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 @@ -283,15 +283,22 @@ function InstallPackage if ($cParams) { $chocoParams += " $cParams" } - # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress + # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){ $chocoParams += " --no-progress" } $cmd = "choco install $pName $chocoParams" Write-Verbose -Message "Install command: '$cmd'" - $packageInstallOuput = Invoke-Expression -Command $cmd - Write-Verbose -Message "Package output $packageInstallOuput" + + $currentProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + + $packageInstallOutput = Invoke-Expression -Command $cmd + + $ProgressPreference = $currentProgressPreference + + Write-Verbose -Message "Package output $packageInstallOutput" # Clear Package Cache Get-ChocoInstalledPackage -Purge @@ -319,7 +326,7 @@ function UninstallPackage if ($pVersion) { $chocoParams += " --version=`"$pVersion`"" } - # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress + # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){ $chocoParams += " --no-progress" } @@ -344,10 +351,10 @@ function IsPackageInstalled param( [Parameter(Position=0, Mandatory)] [string]$pName, - + [Parameter(ParameterSetName = 'RequiredVersion')] [string]$pVersion, - + [Parameter(ParameterSetName = 'MinimumVersion')] [string]$pMinimumVersion ) @@ -470,7 +477,7 @@ Function Upgrade-Package { if ($cParams) { $chocoParams += " $cParams" } - # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress + # Check if Chocolatey version is Greater than 0.10.4, and add --no-progress if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){ $chocoParams += " --no-progress" } @@ -483,9 +490,14 @@ Function Upgrade-Package { throw "$pName is not installed, you cannot upgrade" } + $currentProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + $packageUpgradeOuput = Invoke-Expression -Command $cmd $packageUpgradeOuput | ForEach-Object { Write-Verbose -Message $_ } + $ProgressPreference = $currentProgressPreference + # Clear Package Cache Get-ChocoInstalledPackage -Purge } @@ -497,6 +509,11 @@ function Get-ChocoInstalledPackage { [switch]$NoCache ) + if ([string]::IsNullOrEmpty($env:ChocolateyInstall)) + { + $env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine') + } + $ChocoInstallLP = Join-Path -Path $env:ChocolateyInstall -ChildPath 'cache' if ( -not (Test-Path $ChocoInstallLP)){ New-Item -Name 'cache' -Path $env:ChocolateyInstall -ItemType Directory | Out-Null @@ -528,6 +545,11 @@ function Get-ChocoVersion { [switch]$NoCache ) + if ([string]::IsNullOrEmpty($env:ChocolateyInstall)) + { + $env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine') + } + $chocoInstallCache = Join-Path -Path $env:ChocolateyInstall -ChildPath 'cache' if ( -not (Test-Path $chocoInstallCache)){ New-Item -Name 'cache' -Path $env:ChocolateyInstall -ItemType Directory | Out-Null