Romanitho / Winget-Install

Powershell scripts for Winget with SCCM/Intune
MIT License
202 stars 42 forks source link

winget-detect change #33

Closed KnifMelti closed 2 years ago

KnifMelti commented 2 years ago

Current doesn't function anymore. The way from WAU does:

#Change app to detect [Application ID]
$AppToDetect = "Notepad++.Notepad++"

<# FUNCTIONS #>

Function Get-WingetCmd {

    #Get WinGet Path (if admin context)
    $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
    if ($ResolveWingetPath){
        #If multiple version, pick last one
        $WingetPath = $ResolveWingetPath[-1].Path
    }

    #Get Winget Location in User context
    $WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
    if ($WingetCmd){
        $Script:Winget = $WingetCmd.Source
    }
    #Get Winget Location in System context (WinGet < 1.17)
    elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
        $Script:Winget = "$WingetPath\AppInstallerCLI.exe"
    }
    #Get Winget Location in System context (WinGet > 1.17)
    elseif (Test-Path "$WingetPath\winget.exe"){
        $Script:Winget = "$WingetPath\winget.exe"
    }
    else{
        break
    }
}

<# MAIN #>

#Get WinGet Location Function
Get-WingetCmd

#Get "Winget List AppID"
$InstalledApp = & $winget list --Id $AppToDetect --accept-source-agreements | Out-String

#Return if AppID existe in the list
if ($InstalledApp -match [regex]::Escape($AppToDetect)){
    return "Installed!"
}
Romanitho commented 2 years ago

it works for me 🤔

KnifMelti commented 2 years ago

Hmm, well not until I edited like above it did for me (in SCCM)? The agent just said it's not required (with multiple Winget versions like here) probably cause it couldn't find winget-exe

Romanitho commented 2 years ago

Ohh, I get it, ok. You're totaly right. I didn't update the detection method script, and didn't faced up the case of multiple winget version yet ^^ Thanks for that :)

Romanitho commented 2 years ago

Can you push a PR ? That's your findings :) you deserve credit

KnifMelti commented 2 years ago

Nonono.. ..I'm only working in the background as a Dinosaur :)

Romanitho commented 2 years ago

I'm on it then ;)