mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-07-17 01:10:46 +00:00
33 lines
1.2 KiB
PowerShell
33 lines
1.2 KiB
PowerShell
Function Install-WinUtilProgramWinget {
|
|
param (
|
|
[Parameter(Mandatory=$true)]
|
|
[ValidateSet("Install", "Uninstall")]
|
|
[string]$Action,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
[string[]]$Programs
|
|
)
|
|
|
|
foreach ($program in $Programs) {
|
|
if ([string]::IsNullOrWhiteSpace($program) -or $program -eq "na") {
|
|
continue
|
|
}
|
|
|
|
$source = "winget"
|
|
if ($program.StartsWith("msstore:", [System.StringComparison]::OrdinalIgnoreCase)) {
|
|
$source = "msstore"
|
|
$program = $program.Substring("msstore:".Length)
|
|
}
|
|
|
|
if ($Action -eq 'Install') {
|
|
$arguments = @("install", "--id", $program, "--accept-package-agreements", "--accept-source-agreements", "--source", $source, "--silent")
|
|
} else {
|
|
$arguments = @("uninstall", "--id", $program, "--source", $source, "--silent")
|
|
}
|
|
|
|
Write-WinUtilLog -Component "Package" -Message "$Action winget package: $program (source: $source)"
|
|
$process = Start-Process -FilePath winget -ArgumentList $arguments -NoNewWindow -Wait -PassThru
|
|
Write-WinUtilLog -Component "Package" -Message "$Action winget package completed: $program (exit code: $($process.ExitCode))"
|
|
}
|
|
}
|