From a2d0c8942437487cd0f325cd68a244cab45b9def Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 1 Aug 2024 18:35:45 +0200 Subject: [PATCH] Add dedicated commands for checking software --- .../Windows/Scripts/SoftwareManagement.ps1 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scripts/Windows/Scripts/SoftwareManagement.ps1 b/scripts/Windows/Scripts/SoftwareManagement.ps1 index 1940686a..c0bacc28 100644 --- a/scripts/Windows/Scripts/SoftwareManagement.ps1 +++ b/scripts/Windows/Scripts/SoftwareManagement.ps1 @@ -25,3 +25,34 @@ function Install-SoftwarePackage([Context] $context, [string] $location, [string Remove-Item -Recurse $tempDir; } } + +<# + .SYNOPSIS + Checks whether the specified package has been installed using Chocolatey. + + .PARAMETER Name + The name of the package to check. +#> +function Test-ChocoPackage { + [OutputType([bool])] + param( + [string] $Name + ); + + -not [string]::IsNullOrEmpty((choco list --limit-output --exact $name)); +} + +<# + .SYNOPSIS + Checks whether a command with the specified name exists. + + .PARAMETER Name + The name of the command to check. +#> +function Test-Command { + param ( + [string] $Name + ) + + [bool] (Get-Command $Name -ErrorAction SilentlyContinue); +}