-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinget_upgrade_packages.ps1
More file actions
34 lines (29 loc) · 1.03 KB
/
winget_upgrade_packages.ps1
File metadata and controls
34 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
param (
[string]$excludeStartsWith = "Sonic"
)
# Function to check if a string starts with the specified prefix
function StartsWithPrefix($packageName, $prefix) {
return $packageName.StartsWith($prefix)
}
# Get list of upgradeable packages using winget
$upgradeablePackages = winget upgrade
# Define the regex pattern
$regexPattern = '^.*[\s]([\w\.]+)[\s]+[\d\.]+[\s]+[\d\.]+[\s]+winget$'
# Extract package names using regex
$packageNames = $upgradeablePackages -split "`n" | ForEach-Object {
if ($_ -match $regexPattern) {
$matches[1]
}
}
# Iterate through each package name
foreach ($packageName in $packageNames) {
# Write-Host "parsed: $packageName"
# Check if package name starts with the specified prefix
if (StartsWithPrefix $packageName $excludeStartsWith) {
Write-Host "Skipping upgrade for package: $packageName (starts with '$excludeStartsWith')"
} else {
Write-Host "Upgrading package: $packageName"
# Perform upgrade using winget
winget upgrade $packageName
}
}