forked from Romanitho/Winget-Install
-
Notifications
You must be signed in to change notification settings - Fork 1
/
winget-detect.ps1
53 lines (38 loc) · 1.44 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
42
43
44
45
46
47
48
49
50
51
52
53
#Change app to detect [Application ID]
$AppToDetect = "Notepad++.Notepad++"
<# FUNCTIONS #>
Function Get-WingetCmd {
$WingetCmd = $null
#Get WinGet Path
try {
#Get Admin Context Winget Location
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
#If multiple versions, pick most recent one
$WingetCmd = $WingetInfo[-1].FileName
}
catch {
#Get User context Winget Location
if (Test-Path "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe") {
$WingetCmd = "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe"
}
}
return $WingetCmd
}
<# MAIN #>
#Get WinGet Location Function
$winget = Get-WingetCmd
#Set json export file
$JsonFile = "$env:TEMP\InstalledApps.json"
#Get installed apps and version in json file
& $Winget export -o $JsonFile --accept-source-agreements | Out-Null
#Get json content
$Json = Get-Content $JsonFile -Raw | ConvertFrom-Json
#Get apps and version in hashtable
$Packages = $Json.Sources.Packages
#Remove json file
Remove-Item $JsonFile -Force
# Search for specific app and version
$Apps = $Packages | Where-Object { $_.PackageIdentifier -eq $AppToDetect }
if ($Apps) {
return "Installed!"
}