-
Notifications
You must be signed in to change notification settings - Fork 14
/
Winget-InstallDetection.ps1
54 lines (49 loc) · 1.79 KB
/
Winget-InstallDetection.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
54
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.195
Created on: 3/7/2022 2:14 PM
Created by: Dave Just
Organization:
Filename: WingetInstallDetection.ps1
===========================================================================
.DESCRIPTION
Simple Win32App detection script. Detects the presence of an uninstall key matching the displayname of the variable $SoftwareName.
If a key is matched, return to Intune that the software is installed.
.EXAMPLE
$SoftwareName = 'Chrome' # Search for an uninstall key with Displayname 'Chrome' for Google Chrome
#>
# Edit the software displayname below
$SoftwareName = ''
function Get-RegUninstallKey
{
param (
[string]$DisplayName
)
$ErrorActionPreference = 'Continue'
$UserSID = ([System.Security.Principal.NTAccount](Get-CimInstance Win32_ComputerSystem).UserName).Translate([System.Security.Principal.SecurityIdentifier]).Value
$uninstallKeys = "registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall", "registry::HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall","registry::HKU\$UserSID\Software\Microsoft\Windows\CurrentVersion\Uninstall"
$softwareTable = @()
foreach ($key in $uninstallKeys)
{
$softwareTable += Get-Childitem $key | Get-ItemProperty | where displayname | Sort-Object -Property displayname
}
if ($DisplayName)
{
$softwareTable | Where-Object {$_.displayname -Like "*$DisplayName*"}
}
else
{
$softwareTable | Sort-Object -Property displayname -Unique
}
}
$UninstallKey = Get-RegUninstallKey -DisplayName $SoftwareName
if ($UninstallKey)
{
Write-Output "$($SoftwareName) is installed"
exit 0
}
else
{
exit 1
}