Skip to content

Instantly share code, notes, and snippets.

@skull-squadron
Last active March 15, 2023 03:50
Show Gist options
  • Save skull-squadron/164ffd78e2f6685ba3421decad541cbd to your computer and use it in GitHub Desktop.
Save skull-squadron/164ffd78e2f6685ba3421decad541cbd to your computer and use it in GitHub Desktop.
Windows Workaround a bug in winget that prevents upgrade --all from working
$output = winget upgrade | Out-String
$lines = $output.Split([Environment]::NewLine)
$hdrLine = 0
while (-not $lines[$hdrLine].StartsWith("Name")) {
$hdrLine++
}
$idIdx = $lines[$hdrLine].IndexOf("Id")
$versionIdx = $lines[$hdrLine].IndexOf("Version")
$availableIdx = $lines[$hdrLine].IndexOf("Available")
For ($i = $hdrLine + 1; $i -le $lines.Length; $i++) {
$line = $lines[$i]
if ($line.Length -gt ($availableIdx + 1) -and -not $line.StartsWith('-')) {
$id = $line.Substring($idIdx, $versionIdx - $idIdx).TrimEnd()
winget upgrade --force --accept-source-agreements --accept-package-agreements --exact --id $id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment