Winget and PSADT

Has anyone ever used the “winget” command in PSADT? Install or uninstall options.

1 Like

No - But I too would be interested in hearing others findings / experience as I’m sure we’d have a few use cases

About to embark on that journey myself. I’m sure there’s a better channel for mentioning this, but it would be great to see Winget based functions added as a feature of the toolkit.

1 Like

Yeah, I’ve started to look into it. I add these two variables to the declaration section in the beginning:

[String]$AppInstaller = 'Microsoft.OneDrive' ## Application ID found here: https://winget.run/
[String]$InstallArgs = '/silent' ## Any overrides to the installer need to be specified here!!

Installation section looks like this:

winget.exe install --exact --id $AppInstaller --override $InstallArgs --accept-source-agreements --silent

Uninstall section looks like this:

winget.exe uninstall --exact --id $AppInstaller --accept-source-agreements --silent

Then I use a simple detection script:

[String]$AppInstaller = 'Microsoft.OneDrive' ## Use the A specified in the Deploy-Application.ps1 script

# resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1) {
    $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe) {
    Write-Error "Winget not installed"
}
else {
    $wingetPrg_Existing = & $winget_exe list --id $AppInstaller --exact --accept-source-agreements
    if ($wingetPrg_Existing -like "*$AppInstaller*") {
        Write-Host "Found it!"
    }
}

Seems to work well. If you need to override the standard installation method, use the $InstallArgs variable I defined at the beginning.

Cheers,
phunkymunky

3 Likes