Skip to content

Instantly share code, notes, and snippets.

@alkampfergit
Last active November 25, 2024 17:46
Show Gist options
  • Select an option

  • Save alkampfergit/2f662c07df0ca379c8e8e65e588c687b to your computer and use it in GitHub Desktop.

Select an option

Save alkampfergit/2f662c07df0ca379c8e8e65e588c687b to your computer and use it in GitHub Desktop.

Revisions

  1. alkampfergit revised this gist Mar 7, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion WingetUpgrade.ps1
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ class Software {
    [string]$AvailableVersion
    }

    $upgradeResult = winget upgrade -include--unknown | Out-String
    $upgradeResult = winget upgrade | Out-String

    $lines = $upgradeResult.Split([Environment]::NewLine)

  2. alkampfergit created this gist Feb 16, 2022.
    70 changes: 70 additions & 0 deletions WingetUpgrade.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    class Software {
    [string]$Name
    [string]$Id
    [string]$Version
    [string]$AvailableVersion
    }

    $upgradeResult = winget upgrade -include--unknown | 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 $i 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 in real package and split accordingly
    $upgradeList = @()
    For ($i = $fl + 1; $i -le $lines.Length; $i++)
    {
    $line = $lines[$i]
    if ($line.Length -gt ($availableStart + 1) -and -not $line.StartsWith('-'))
    {
    $name = $line.Substring(0, $idStart).TrimEnd()
    $id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
    $version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
    $available = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
    $software = [Software]::new()
    $software.Name = $name;
    $software.Id = $id;
    $software.Version = $version
    $software.AvailableVersion = $available;

    $upgradeList += $software
    }
    }


    $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",
    "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)"
    }
    }