forked from Romanitho/Winget-Install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinget-detect.ps1
41 lines (32 loc) · 1.16 KB
/
winget-detect.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#Change app to detect [Application ID]
$AppToDetect = "Notepad++.Notepad++"
<# FUNCTIONS #>
Function Get-WingetCmd {
#Get WinGet Path (if admin context)
$ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
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
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!"
}