Winget Pre-Install

Troubleshooting the Winget Pre-Install

Troubleshooting Winget Pre-Install with Pckgr

Setup PowerShell to Run as SYSTEM

To effectively test PowerShell scripts as the System account, follow the guidelines provided in the PowerShell Toolbox. This ensures that your scripts have the appropriate permissions to execute and interact with system-level components.

Running the Winget Check Script

Execute the following script to verify the installation and version of Winget on your system. The script will identify the path to the Winget executable(s), determine the latest version, and check if it meets the required version criteria. Please run the script using the STSYEM account and report any errors encountered during execution.

##*===============================================
##* Check Winget
##*===============================================

# Get the path to the Winget executable(s)
$wingetPaths = Get-ChildItem 'C:\Program Files\WindowsApps' -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -like 'winget.exe' } | Select-Object -ExpandProperty FullName -ErrorAction SilentlyContinue

if($wingetPaths.Count -gt 1)
{
    # Create a dictionary to store the version numbers of each Winget.exe file
    $versions = @{}

    # Loop through each Winget.exe path and extract its version number
    foreach ($path in $wingetPaths) {
        $wingetversion = $path.Split("_")[1]
        if (-not $versions.ContainsKey($wingetversion)) {
            $versions[$wingetversion] = $path
        }
    }
    # Get the latest version number
    $latestVersion = [version]($versions.Keys | Sort-Object -Descending | Select-Object -First 1)
    $versionToFind = "$latestVersion"
    $wingetexe = $wingetPaths | Where-Object { $_ -match $versionToFind }
}
else
{
    $wingetexe = $wingetPaths
}

$wingettest = & $wingetexe
if ($wingettest -like "*Windows Package Manager*") {
    Write-Host "Winget Found, checking version"
    $wingetVersion = & $wingetexe --version
    # Removes the leading 'v' and anything following a dash
    $wingetVersion = $wingetVersion -replace '^v|-.+$', ''
    if ([Version]$wingetVersion -ge [Version]'1.6.3482') {    
        Write-Host 'Winget is up to date'
    } else {
        Write-Host 'Winget is not up to date'
    }
} else {
    Write-Host 'Winget not Found'
}

Script Breakdown

  1. Retrieve Winget Paths:

    • The script searches for winget.exe within the C:\Program Files\WindowsApps directory and retrieves the full paths of any found instances.

  2. Identify Latest Version:

    • If multiple winget.exe files are found, the script extracts and sorts their version numbers to identify the latest one.

  3. Check Winget Installation:

    • The script runs the identified winget.exe and checks for the presence of "Windows Package Manager" in its output.

  4. Verify Winget Version:

    • The version of Winget is compared to the required version (1.6.3482). The script provides feedback on whether Winget is up to date or not.

Reporting Issues

After running the script, please report any errors or unexpected outputs. This information will help diagnose and resolve any issues related to Winget installation or version discrepancies.

Last updated