From 566e2b6b4e9f95ce6e4eff50d4cc0390893acf4e Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 27 Aug 2024 01:25:32 +0200 Subject: [PATCH] Only install PowerShell module if necessary --- scripts/Common/Scripts/SoftwareManagement.ps1 | 15 +++++++++++++++ scripts/Windows/OS/Install.ps1 | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/Common/Scripts/SoftwareManagement.ps1 b/scripts/Common/Scripts/SoftwareManagement.ps1 index 51cb6a21..95207684 100644 --- a/scripts/Common/Scripts/SoftwareManagement.ps1 +++ b/scripts/Common/Scripts/SoftwareManagement.ps1 @@ -103,3 +103,18 @@ function Test-PSPackage { [bool] (Get-Package $Name -ErrorAction SilentlyContinue); } + +<# + .SYNOPSIS + Checks whether a module with the specified name is installed. + + .PARAMETER Name + The name of the module to check. +#> +function Test-PSModule { + param( + [string] $Name + ) + + [bool](Get-Module -ListAvailable $Name -ErrorAction SilentlyContinue); +} diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 664ef6ec..498891a8 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -179,8 +179,10 @@ $null = New-Module { }; } - Install-Module -Scope AllUsers -AcceptLicense -Force $module[0] @parameters; - Import-Module $module[0]; + if (-not (Test-PSModule $module[0])) { + Install-Module -Scope AllUsers -AcceptLicense -Force -AllowClobber $module[0] @parameters; + Import-Module $module[0]; + } } . "$PSScriptRoot/../Software/PinnedItem/Manage.ps1";