Files
winutil/functions/private/Install-WinUtilProgramWinget.ps1
T

48 lines
1.6 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
Function Install-WinUtilProgramWinget {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Manages the provided programs using Winget
.PARAMETER ProgramsToInstall
A list of programs to manage
.PARAMETER manage
The action to perform on the programs, can be either 'Installing' or 'Uninstalling'
.NOTES
The triple quotes are required any time you need a " in a normal script block.
+3
2023-03-07 12:28:00 -08:00
#>
+2
2023-05-09 13:14:27 -05:00
param(
$ProgramsToInstall,
$manage = "Installing"
)
+3
2023-03-07 12:28:00 -08:00
$x = 0
$count = $($ProgramsToInstall -split ",").Count
+2
2023-05-09 13:14:27 -05:00
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
+3
2023-03-07 12:28:00 -08:00
Foreach ($Program in $($ProgramsToInstall -split ",")){
2023-10-19 17:12:55 -05:00
+2
2023-05-09 13:14:27 -05:00
Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100)
if($manage -eq "Installing"){
+8
2024-03-28 12:39:23 -07:00
# --scope=machine when installing non-UWP apps with winget fails with error code 0x80070005.
# Removed argument while testing new Winget install method.
# Open issue on winget-cli github repo: https://github.com/microsoft/winget-cli/issues/3936
Start-Process -FilePath winget -ArgumentList "install -e --accept-source-agreements --accept-package-agreements --silent $Program" -NoNewWindow -Wait
+2
2023-05-09 13:14:27 -05:00
}
if($manage -eq "Uninstalling"){
+8
2024-03-21 16:23:24 -07:00
Start-Process -FilePath winget -ArgumentList "uninstall -e --accept-source-agreements --purge --force --silent $Program" -NoNewWindow -Wait
}
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
$X++
}
+2
2023-05-09 13:14:27 -05:00
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
+3
2023-03-07 12:28:00 -08:00
+8
2024-03-21 16:23:24 -07:00
}