From 79bb81cbff5964b785ebb0505f1e198f064f1200 Mon Sep 17 00:00:00 2001 From: dinger1986 Date: Thu, 13 Mar 2025 16:29:37 +0000 Subject: [PATCH] Update Win_WinGet_Manage_Apps.ps1 --- scripts/Win_WinGet_Manage_Apps.ps1 | 43 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/scripts/Win_WinGet_Manage_Apps.ps1 b/scripts/Win_WinGet_Manage_Apps.ps1 index f92654a6..58bf7ed9 100644 --- a/scripts/Win_WinGet_Manage_Apps.ps1 +++ b/scripts/Win_WinGet_Manage_Apps.ps1 @@ -1,26 +1,27 @@ <# .SYNOPSIS - This will install software using the winget which should be on any up to date Windows PC + This will install software using winget which should be on any up to date Windows PC .DESCRIPTION For installing packages using winget. .PARAMETER Mode - 6 options: install, uninstall, search, update, show or upgrade. + 5 options: install, uninstall, search, show, or upgrade. .PARAMETER PackageName Use this to specify which software to install eg: PackageName google.chrome .EXAMPLE - -PackageName googlechrome + -PackageName google.chrome .EXAMPLE - -Mode upgrade + -Mode upgrade # Upgrades all packages .EXAMPLE - -Mode uninstall -PackageName google.chrome + -Mode upgrade -PackageName google.chrome # Upgrades only specified package .EXAMPLE - -Mode update -PackageName google.chrome - .EXAMPLE (to show updates available) - -Mode show + -Mode uninstall -PackageName google.chrome + .EXAMPLE (to show package information) + -Mode show -PackageName google.chrome .NOTES 9/2021 v1 Initial release by @silversword411 and @bradhawkins 11/14/2021 v1.1 Fixing typos and logic flow - 18/08/2022 edited script to work with winget + 18/08/2022 edited script to work with winget + 03/12/2025 Modified to remove update, fix upgrade behavior, and fix show mode to use correct command by @jd on Discord #> param ( @@ -28,28 +29,30 @@ param ( [string] $Mode = "install" ) -$wingetloc=(Get-Childitem -Path "C:\Program Files\WindowsApps" -Include winget.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -Last 1 | %{$_.FullName} | Split-Path) +$wingetloc = (Get-Childitem -Path "C:\Program Files\WindowsApps" -Include winget.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -Last 1 | %{$_.FullName} | Split-Path) cd $wingetloc $ErrorCount = 0 -if ($Mode -eq "show") { - .\winget.exe upgrade --accept-source-agreements - Exit 0 -} - -if ($Mode -ne "update" -and !$PackageName) { +# Require PackageName for all modes except upgrade +if ($Mode -ne "upgrade" -and !$PackageName) { write-output "No package name provided, please include Example: `"-PackageName google.chrome`" `n" Exit 1 } -if ($Mode -eq "upgrade") { - .\winget.exe upgrade --all --accept-source-agreements +if ($Mode -eq "show") { + .\winget.exe show $PackageName --accept-source-agreements Exit 0 } -if ($Mode -eq "update") { - .\winget.exe upgrade $PackageName --accept-source-agreements +if ($Mode -eq "upgrade") { + if ($PackageName) { + # Upgrade specific package if PackageName is provided + .\winget.exe upgrade $PackageName --accept-source-agreements + } else { + # Upgrade all packages if no PackageName is provided + .\winget.exe upgrade --all --accept-source-agreements + } Exit 0 }