Skip to content

Instantly share code, notes, and snippets.

@jpcranford
Created July 9, 2025 14:20
Show Gist options
  • Save jpcranford/8f5ac41878cb485cd9f52dea5e907620 to your computer and use it in GitHub Desktop.
Save jpcranford/8f5ac41878cb485cd9f52dea5e907620 to your computer and use it in GitHub Desktop.
A simple Powershell script to install an app using winget when running as System. Compatible with RMMs, tested on Syncro.
# EDIT THESE TO CHANGE THE APP TO INSTALL
$wingetAppId = "7zip.7zip" # This script will only install an exact match, so double-check.
$customInstallerArgs = "" # These will vary by app. Check the EXE/MSI documentation.
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($ResolveWingetPath){
$WingetPath = $ResolveWingetPath[-1].Path
}
$Wingetpath = Split-Path -Path $WingetPath -Parent
cd $wingetpath
$wingetResult = .\winget.exe install -h -e --id $wingetAppId --disable-interactivity --accept-source-agreements --custom $customInstallerArgs # Add --no-upgrade here to prevent updating existing installations
if ($LASTEXITCODE -eq 0) {
Write-Output "$wingetAppId installed succesfully."
} else {
if ($wingetResult -match "A package version is already installed. Installation cancelled.") {
Write-Output "$wingetAppId already installed!"
exit 0
} elseif ($wingetResult -match "Successfully installed") {
Write-Output "Script errored, but $wingetAppId installed succesfully."
exit 0
} else {
Write-Output $wingetResult
exit 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment