do you have a script to install apps with Winget on a fresh install of Windows.

atarione

2[H]4U
Joined
Mar 17, 2011
Messages
2,516
I have a number of machines and like to mess about testing VM's as well... So I have this script to install most of the software I want on a new machine running windows utilizing winget. Been adding programs to this as I think of it... if anyone has any other good ideas for programs to add do let me know? Curious if any of y'all have attempted to streamline installing software on a fresh install?

@echo off
setlocal enabledelayedexpansion

:: List of application IDs
set apps=Microsoft.WindowsTerminal.Preview Microsoft.PowerToys VideoLAN.VLC Mozilla.Firefox brave.brave Spotify.Spotify PrimateLabs.Geekbench.6 Audacity.Audacity CPUID.HWMonitor TheDocumentFoundation.LibreOffice

for %%A in (%apps%) do (
echo ---------------------------------------
echo Processing %%A...

:: Check if the app is installed by capturing the list output
winget list --id %%A > temp_check.txt 2>&1

findstr /C:"No installed package found" temp_check.txt >nul
if !errorlevel! equ 0 (
echo %%A not installed. Installing...
winget install --id %%A --silent --accept-source-agreements --accept-package-agreements
) else (
echo %%A is installed. Attempting upgrade...
winget upgrade --id %%A --silent --accept-source-agreements --accept-package-agreements
if !errorlevel! neq 0 (
echo Upgrade failed for %%A or no update available.
)
)

echo.
)

del temp_check.txt >nul 2>&1
endlocal
 
really depends what the machines are for, notepad++, 7zip, SumatraPDF (or something you like), curl, python, steam/gog, everything (powerful search indexer), some email client (thunderbird or others), process explorer,
 
7zip, Notepad++, HWinfo, CrystalDiskInfo, WinDirStat, CrystalDiskMark, Google.Chrome, and Teamviewer are on my shortlist.
 
install already handles upgrades, don't think you need to waste effort detecting anything

https://learn.microsoft.com/en-us/windows/package-manager/winget/install
https://github.com/microsoft/winget...windows/package-manager/winget/returnCodes.md

If you really want to explicitly loop over things...

Bash:
$NO_APPLICABLE_UPDATE = -1978335189

$apps = @(
    "Mozilla.Firefox"
    "7zip.7zip"
    "VideoLAN.VLC"
    "Microsoft.VisualStudioCode"
)

foreach ($app in $apps) {
    winget install `
        --id $app `
        --exact `
        --silent `
        --accept-package-agreements `
        --accept-source-agreements `
        --disable-interactivity

    # If you want to explicitly call out any additional status codes...
    switch ($LASTEXITCODE) {
        0 {
            Write-Output "$app installed or updated successfully."
        }

        $NO_APPLICABLE_UPDATE {
            Write-Output "$app is already installed and up to date."
        }

        default {
            Write-Error "Failed to install or update $app (exit code: $LASTEXITCODE)"
        }
    }
}


Or just space delimit apps and call it a day.

Bash:
winget install Mozilla.Firefox 7zip.7zip VideoLAN.VLC Microsoft.VisualStudioCode ...
 
Back
Top