Skip to main content

So I have created this worklet, but nothing seem to happen when I try to run it manually on a computer. Any idea whats wrong?

Evalution:

# Runs 'winget upgrade' to dertimne any updates and save the output
$output = winget upgrade | Out-String
 
# looking for a specific text
if ($output -match "No applicable update found.") {
    # no updates found
    exit 0
} else {
    # uådates found
    exit 1
}

 

Remediation :

# Runs a elevated PowerShell session to update all
$scriptBlock = {
    winget upgrade --all --silent --accept-package-agreements --accept-source-agreements
}
 
# Runs the script with admin priviliges 
Start-Process powershell -ArgumentList "-Command", $scriptBlock -Verb RunAs

Hi Jonas,

The issue here is triggering winget from an absolute path since it isn’t really something ‘system’ can invoke on your behalf. Here are two results from my Activity Log, one from indirect invocation and one from direct invocation:
 

As you can see, the first result (on bottom) has zero data in it. Here is the difference in code. The commented out line is the equivalent to what you are attempting to do, vs the active code which specifies an execution directory where winget is found:
 


Use the following code chunk to make the wheels turn:
 

$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
if ($ResolveWingetPath){
$WingetPath = $ResolveWingetPathW-1].Path
}

$config
Set-Location $wingetpath
.\winget.exe list --upgrade-available

#winget list --upgrade-available

 


Reply