Add functions for installing choco and winget packages

This commit is contained in:
Manuel Thalmann 2024-08-07 13:22:12 +02:00
parent 6662828dbe
commit 34d6ced776

View file

@ -4,8 +4,60 @@
. "$PSScriptRoot/../Types/InstallerAction.ps1";
$null = New-Module {
. "$PSScriptRoot/SoftwareManagement.ps1";
. "$PSScriptRoot/../Types/InstallerAction.ps1";
$userArgument = "name";
<#
.SYNOPSIS
Installs the specified packages using chocolatey.
.PARAMETER Names
The names of the packages to install.
#>
function Install-ChocoPackage {
param(
[switch] $Force,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Names
)
[System.Collections.ArrayList] $Names = $Names;
if (-not ($Force.IsPresent)) {
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
if (Test-ChocoPackage $Names[$i]) {
$Names.RemoveAt($i);
}
}
}
if ($Names.Count -ge 1) {
choco install -y $Names;
}
}
<#
.SYNOPSIS
Installs the specified packages using `winget`.
.PARAMETER Names
The names of the packages to install.
#>
function Install-WingetPackage {
param(
[switch] $Force,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Names
)
foreach ($name in $Names) {
if ($Force.IsPresent -and -not (Test-WingetPackage $name)) {
winget install --accept-source-agreements --accept-package-agreements -e --id $name;
}
}
}
function Start-SoftwareInstaller {
param(
[string] $Name,