From 1cb2f9a21e6a0dd698a92b094894bdc02c7de9d4 Mon Sep 17 00:00:00 2001 From: Koos Goossens Date: Mon, 28 Nov 2022 22:35:43 +0100 Subject: [PATCH] Better installing/importing of PS modules --- powershell-script/AzSentinelPricingOptimizer.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/powershell-script/AzSentinelPricingOptimizer.ps1 b/powershell-script/AzSentinelPricingOptimizer.ps1 index 555f6a6..719a8ae 100644 --- a/powershell-script/AzSentinelPricingOptimizer.ps1 +++ b/powershell-script/AzSentinelPricingOptimizer.ps1 @@ -89,15 +89,21 @@ if ($updateArmParameters) { ) Write-Host "Installing/Importing PowerShell modules..." -ForegroundColor DarkGray $modulesToInstall | ForEach-Object { - if (-not (Get-Module -ListAvailable -All $_)) { - Write-Host "Module [$_] not found, installing..." -ForegroundColor DarkGray + if (-not (Get-Module -ListAvailable $_)) { + Write-Host " ┖─ Module [$_] not found, installing..." -ForegroundColor DarkGray Install-Module $_ -Force + } else { + Write-Host " ┖─ Module [$_] already installed." -ForegroundColor DarkGray } } $modulesToInstall | ForEach-Object { - Write-Host "Importing Module [$_]" -ForegroundColor DarkGray - Import-Module $_ -Force + if (-not (Get-InstalledModule $_)) { + Write-Host " ┖─ Module [$_] not loaded, importing..." -ForegroundColor DarkGray + Import-Module $_ -Force + } else { + Write-Host " ┖─ Module [$_] already loaded." -ForegroundColor DarkGray + } } # (Re-)setting Variables