You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Software {
[string]$Name
[string]$Id
[string]$Version
[string]$AvailableVersion
}
$upgradeResult = winget upgrade | Out-String
$lines = $upgradeResult.Split([Environment]::NewLine)
# Find the line that starts with Name, it contains the header
$fl = 0
while (-not $lines[$fl].StartsWith("Name")) {
$fl++
}
# Line $fl has the header, we can find char where we find ID and Version
$idStart = $lines[$fl].IndexOf("Id")
$versionStart = $lines[$fl].IndexOf("Version")
$availableStart = $lines[$fl].IndexOf("Available")
$sourceStart = $lines[$fl].IndexOf("Source")
# Now cycle through the real package list and split accordingly
$upgradeList = @()
For ($i = $fl + 1; $i -lt $lines.Length; $i++) {
$line = $lines[$i]
# Ensure that the line has enough length and does not start with a separator like '-'
if ($line.Length -gt $availableStart -and -not $line.StartsWith('-')) {
$name = $line.Substring(0, $idStart).TrimEnd()
if ($line.Length -ge $sourceStart) {
# Proceed if the line has enough length for all fields
$id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
$version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
$available = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
# Create the software object
$software = [Software]::new()
$software.Name = $name
$software.Id = $id
$software.Version = $version
$software.AvailableVersion = $available
$upgradeList += $software
} else {
# Handle lines that don't contain enough data
Write-Host "Skipping line due to insufficient data: $line"
}
}
}
$upgradeList | Format-Table
$toSkip = @(
'ArtifexSoftware.GhostScript',
'Microsoft.VC++2013Redist-x64',
'MongoDB.Server',
"Microsoft.VC++2015-2019Redist-x64",
"Microsoft.VC++2015-2019Redist-x86",
"Microsoft.VC++2013Redist-x86",
"Python.Python.3.12",
"Microsoft.OneDrive"
)
foreach ($package in $upgradeList) {
if (-not ($toSkip -contains $package.Id)) {
Write-Host "Going to upgrade package $($package.Id)"
& winget upgrade $package.Id
} else {
Write-Host "Skipped upgrade to package $($package.Id)"
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Error:
Fixed here:
Beta Was this translation helpful? Give feedback.
All reactions