Skip to main content

Upgrate WindowsNotepad (Store)

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "notepad-upgrade.ps1"

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "notepad-upgrade.ps1"

$wpkg = Get-ChildItemAppxPackage -Path (Join-PathAllUsers -Path $env:ProgramFiles -ChildPath 'WindowsApps') -Filter winget.exe -Recurse -ErrorAction SilentlyContinue |
     Where-Object { $_.Directory.Name -like 'Microsoft.DesktopAppInstaller*' }DesktopAppInstaller |
       Sort-Object { [version]($_.Directory.Name -replace 'Microsoft.DesktopAppInstaller_([\d\.]+)_.*','$1') }Version -Descending |
       Select-Object -First 1

if (-ExpandPropertynot FullName$pkg) {
    Write-Output "Desktop App Installer package not found on this host."
    exit 1
}

$w = Join-Path -Path $pkg.InstallLocation -ChildPath 'winget.exe'

if (-not (Test-Path $w)) {
    Write-Output "winget.exe not found onat thisexpected host."path: $w"
    exit 1
}

& $w upgrade --id 9MSMLRH6LZF3 --source msstore --accept-package-agreements --accept-source-agreements --silent
$code = $LASTEXITCODE

switch ($code) {
    0            { Write-Output "Upgraded successfully."; exit 0 }
    -1978335189  { Write-Output "Already at latest version."; exit 0 }
    -1978335215  { Write-Output "Notepad not installed - skipped."; exit 0 }
    default      { Write-Output "winget exited with code $code"; exit $code }
}