From 8a43c0bc5be704d0101dfddd3b9cb079f3d61d9f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 27 Aug 2024 01:57:46 +0200 Subject: [PATCH] Prevent unnecessary installation actions --- scripts/Common/Software/PowerShell/Module.ps1 | 9 ++++++++- scripts/Windows/Software/PinnedItem/Manage.ps1 | 17 ++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/Common/Software/PowerShell/Module.ps1 b/scripts/Common/Software/PowerShell/Module.ps1 index a9cc4113..9ccb5334 100644 --- a/scripts/Common/Software/PowerShell/Module.ps1 +++ b/scripts/Common/Software/PowerShell/Module.ps1 @@ -34,7 +34,14 @@ $null = New-Module { ) $env:PENDING_MODULE_NAME = $Arguments.Name; - $installAction = { Install-Module -Scope AllUsers -Force $env:PENDING_MODULE_NAME @args }; + + $installAction = { + $module = $env:PENDING_MODULE_NAME; + + if (-not (Get-Module -ListAvailable $module -ErrorAction SilentlyContinue)) { + Install-Module -Scope AllUsers -Force $module @args; + } + }; if (-not $Arguments.NativeOnly) { & $installAction -AcceptLicense; diff --git a/scripts/Windows/Software/PinnedItem/Manage.ps1 b/scripts/Windows/Software/PinnedItem/Manage.ps1 index 4500e586..bba3e2d6 100644 --- a/scripts/Windows/Software/PinnedItem/Manage.ps1 +++ b/scripts/Windows/Software/PinnedItem/Manage.ps1 @@ -21,12 +21,15 @@ Start-SoftwareInstaller @parameters -Installer { [hashtable] $Arguments ) - $feature = "NetFx3"; - - if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") { - Write-Host "Enabling ``$feature`` featureā€¦"; - choco install --source windowsFeatures -y $feature; - } - + $module = $Arguments.Name; & $Arguments.Installer @PSBoundParameters; + + if (-not (& { powershell -NoProfile -Command "Import-Module $module; exit ([bool]`$Error)" 2> $null; $?; })) { + $feature = "NetFx3"; + + if ((Get-WindowsOptionalFeature -Online -FeatureName $feature).State -ne "Enabled") { + Write-Host "Enabling ``$feature`` featureā€¦"; + choco install --source windowsFeatures -y $feature; + } + } }