Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions scripts/Win_WinGet_Manage_Apps.ps1
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
<#
.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 (
[string] $PackageName,
[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
}

Expand Down