This command line will upgrade many things, run it in administrative shell:
winget upgrade --all --include-unknown
Don’t try this with Autodesk products installed, and there are probably other situations to watch for too.
This command line will upgrade many things, run it in administrative shell:
winget upgrade --all --include-unknown
Don’t try this with Autodesk products installed, and there are probably other situations to watch for too.
It’s built into most OEM installs of Windows 10 and 11, and can often be installed. On server builds it’s touch and go.
To see if you have it, try winget list
from CMD or Powershell.
One good way to test it, is to install Microsoft .NET framework (SDK) 6, thus, from administrative Powershell:
winget install --id Microsoft.DotNet.Runtime.6 --silent --accept-source-agreements
I learned just now that if you add other seemingly valuable options to the one above, e.g., --scope machine
, at least while running as SYSTEM, it will fail citing package not found. So you’ll want to test carefully.
Here’s one proven just now for 7zip (there’s a “search” option in winget to get the ID):
winget install --exact --id 7zip.7zip --accept-package-agreements --silent --scope machine
Here’s one for Google Chrome, needs a bit of extra:
winget.exe install --exact --id Google.Chrome --silent --accept-package-agreements --accept-source-agreements --scope machine
And here’s a way to upgrade everything Winget can upgrade. There are some systems to not use this on, e.g., anything with some Autodesk products:
winget upgrade --all --include-unknown
If you do want to use it from the SYSTEM account, in scripting, it gets interesting. You’ll want to first run the below, and then winget will run as expected.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Function to find the path to winget.exe function Find-WinGet-Path { # Get the WinGet path (for use when running in SYSTEM context). $WinGetPathToResolve = Join-Path -Path $ENV:ProgramFiles -ChildPath 'WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe' $ResolveWinGetPath = Resolve-Path -Path $WinGetPathToResolve | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } if ($ResolveWinGetPath) { # If we have multiple versions - use the latest. $WinGetPath = $ResolveWinGetPath[-1].Path } # Get the User-Context WinGet exe location. $WinGetExePath = Get-Command -Name winget.exe -CommandType Application -ErrorAction SilentlyContinue # Select the correct WinGet exe if (Test-Path -Path (Join-Path $WinGetPath 'winget.exe')) { # Running in SYSTEM-Context. $WinGet = Join-Path $WinGetPath 'winget.exe' } elseif ($WinGetExePath) { # Get User-Context if SYSTEM-Context not found. $WinGet = $WinGetExePath.Path } else { Write-Output 'WinGet not Found!' Stop-Transcript exit 1 } # Return WinGet path return ($WinGet -replace '\winget.exe','') } Function Add-PathVariable { param ( [string]$addPath ) if (Test-Path $addPath){ $regexAddPath = [regex]::Escape($addPath) $arrPath = $env:Path -split ';' | Where-Object {$_ -notMatch "^$regexAddPath\\?"} $env:Path = ($arrPath + $addPath) -join ';' } else { Throw "'$addPath' is not a valid path." } } Add-PathVariable (Find-Winget-Path)
Installing has been even more interesting. I’ve tried a lot of things. The below worked very well recently on Server 2019 as well as Server 2022. Sometimes it fails once and has to be re-run. It is a script which installs prerequisites, and installs another script called winget-install
. After the installations, it will run winget-install. Once successful, winget runs.
#begin script [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force > $null Function PrepareModule { param( [string]$ModuleName ) "Preparing Powershell environment: Getting online " + $ModuleName + " info..." $OnlineModuleInfo = Find-Module $ModuleName -Repository PSGallery "Preparing Powershell environment: Getting local " + $ModuleName + " info (if exists)..." $LocalModuleInfo = Get-InstalledModule $ModuleName -ErrorAction SilentlyContinue > $null If ($OnlineModuleInfo.Version -ne $LocalModuleInfo.Version) { "Preparing Powershell environment: Removing old " + $ModuleName + " (if exists)..." Uninstall-Module -Name $ModuleName -ErrorAction SilentlyContinue > $null "Preparing Powershell environment: Installing new " + $ModuleName + "..." Install-Module -Name $ModuleName -Repository PSGallery "Preparing Powershell environment: Importing new " + $ModuleName + "..." Import-Module -Name $ModuleName } } "Setting up to use Powershell Gallery..." Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force Install-Module PowerShellGet -Force Set-PSRepository -InstallationPolicy Trusted -Name PSGallery PrepareModule("NuGet") Install-Script -Name winget-install winget-install #End script
HP Support Assistant is the oft-default tool, not suitable for automation. It does work, but often misses items, and sometimes just generally coughs. There is also the HP Image Assistant:
ftp.ext.hp.com/pub/caps-softpaq/cmit/HPIA.html
Its primary purpose is maintaining reference images, but it has a great command-line mode for full automatic downloads and updates. Download the installer, complete it, close the GUI tool, open Powershell or CMD, CD to the folder it created in command-line (it’s C:\SWSETUP\something), and run:
.\HPImageAssistant /Operation:Analyze /Category:All,Accessories /selection:All /action:Install /silent /reportFolder:c:\HPIA\Report /softpaqdownloadfolder:c:\HPIA\download
Then monitor its behavior in TASKMGR, and see the downloads piling up in C:\HPIA\download. If it needs a reboot, it will do it automatically. Even if it doesn’t, reboot is recommended, just to keep everything as smooth as possible.
Best I know is Dell Command Update. Can be installed using winget:
winget install Dell.CommandUpdate.Universal
This is a GUI tool, does a very good job.
This method uses Powershell module PsWindowsUpdate.
First, a complete script which gets the module in and updates everything available from Microsoft, including patches and drivers and firmware:
#begin script [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Set-Executionpolicy RemoteSigned -Scope Process -Force Install-PackageProvider -Name NuGet -Force -ErrorAction 'SilentlyContinue' > $null Set-PSRepository -Name PSGallery -InstallationPolicy Trusted If (Get-InstalledModule -Name PsWindowsUpdate -ErrorAction 'SilentlyContinue') { Update-Module -Name PSWindowsUpdate -Force } Else { Install-Module -Name PSWindowsUpdate -Force } Import-Module PSWindowsUpdate Install-WindowsUpdate -AcceptAll -AutoReboot # end script
Next, the bits. We do need to install and keep up a module.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Set-Executionpolicy RemoteSigned -Scope Process -Force Install-PackageProvider -Name NuGet -Force -ErrorAction 'SilentlyContinue' > $null Set-PSRepository -Name PSGallery -InstallationPolicy Trusted If (Get-InstalledModule -Name PsWindowsUpdate -ErrorAction 'SilentlyContinue') { Update-Module -Name PSWindowsUpdate -Force } Else { Install-Module -Name PSWindowsUpdate -Force } Import-Module PSWindowsUpdate
Then we can check the list of available updates:
Get-WindowsUpdate
And then we probably want to actually do updates. There are good reasons and multiple methods to be careful. Alas, thus far, there does not appear to be a way to install updates a given number of days after release, e.g., 30, so as to give Microsoft time to respond to issues. Here is a glancing overview of what we do have:
Install-WindowsUpdate -NotCategory "Drivers","Service Packs","FeaturePacks" -NotTitle "preview" -AcceptAll
And to do it while ignoring reboot:
Install-WindowsUpdate -NotCategory "Drivers","Service Packs","FeaturePacks" -NotTitle "preview" -AcceptAll -IgnoreReboot
The -IgnoreReboot
ignores all relevant reboot automata. -NotTitle "preview"
omits all updates with the word “preview” in their name.
But sometimes, e.g. with a new PC install, we’ll want to install all updates and reboot automatically:
Install-WindowsUpdate -AcceptAll -AutoReboot
Install-WindowsUpdate -NotKBArticleID KB1234567 -AcceptAll
Install-WindowsUpdate -NotKBArticleID KB1234567 -AcceptAll -IgnoreReboot
Install-WindowsUpdate -AcceptAll -NotKBArticleID "KB1234567,KB7654321"
-NotTitle
and -NotUpdateID
.Reset-WUComponents
Get-Command -Module PSWindowsUpdate
Get-Help
works for all of them.
To do this, one must set a registry entry, this is Powershell:
$registryPath = "HKLM:\SYSTEM\Setup\MoSetup"; If ( !(Test-Path $registryPath) ) { New-Item -Path $registryPath -Force; }; New-ItemProperty -Path $registryPath -Name "AllowUpgradesWithUnsupportedTPMOrCPU" -Value 1 -PropertyType DWORD -Force;
then download the ISO (not the recommended upgrader app), unpack it, and run setup.exe.
This is a curious method, seemingly very reliable, and it has many different builds, including 22H2, 23H2, 24H2 as of right now. Here’s the last 22H2:
uupdump.net/selectlang.php?id=0cda15f9-a14a-4adf-bb3c-2ce79d0de621
It is not the ISO itself, it is a script setup which uses OS resources to build an ISO.
Here it is:
It’s also available via Winget: winget install "Lenovo System Update"
This one works very well indeed. It does need a bit more technical intervention:
A very interesting .EXE which appears to be able to upgrade Build 1909 directly to 22H2.