-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptRule.ps1
76 lines (67 loc) · 2.95 KB
/
ScriptRule.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#Software test-list arrays
[string[]]$SoftwareNameTestList = @(
"McAfee Endpoint Security Firewall",
"McAfee Endpoint Security Platform",
"McAfee Endpoint Security Threat Prevention",
"McAfee Endpoint Security Web Control"
)
[string[]]$SoftwareVersionTestList = @(
"10.7.0",
"10.7.0",
"10.7.0",
"10.7.0"
)
##### DO NOT EDIT BELOW ####
$ErrorActionPreference = 'SilentlyContinue'
$Script:DetectionSuccessful = $Null
$Script:SoftwareVersionTable = $Null
#All possible registry paths containing un-install info
[string[]]$RegistryUninstallPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
)
#If test-list array element counts don't match, fail
if (($SoftwareNameTestList.Count) -eq ($SoftwareVersionTestList.Count)) {
#With each registry path build a table of installed software
foreach ($RegistryPath in $RegistryUninstallPaths) {
$RegistryFolders = (Get-ChildItem $RegistryPath -Name)
$SoftwareVersionTable += $(foreach ($Folder in $RegistryFolders) { (Get-ItemProperty -Path "$RegistryPath\$Folder") | Select-Object DisplayName, DisplayVersion })
}
#Step through each test-list element reformat version data
for ($G = 0; $G -lt ($SoftwareNameTestList.Count); $G++) {
$SoftwareNameTestItem = $SoftwareNameTestList[$G]
$SoftwareVersionTestItem = $SoftwareVersionTestList[$G]
$SoftwareVersionTestItem = [System.Version]$SoftwareVersionTestItem
$SoftwareNameTestItemExists = $False
#Step through each software installed element reformat version data
foreach ($Record in $SoftwareVersionTable) {
$SoftwareNameInstalled = ($Record.DisplayName)
$SoftwareVersionInstalled = ($Record.DisplayVersion)
$SoftwareVersionInstalled = [System.Version]$SoftwareVersionInstalled
#Compare test-list software name and version number against installed software
#Installed software version must be >= the test-list version, this prevents detection method failure if the installed software is newer than that being installed.
#At first failure break out of loop, detection has failed
if ($SoftwareNameInstalled -eq $SoftwareNameTestItem) {
$SoftwareNameTestItemExists = $True
if (($SoftwareVersionInstalled -ge $SoftwareVersionTestItem) -and (!($DetectionSuccessful -eq $False))) {
$DetectionSuccessful = $True
}
else {
$DetectionSuccessful = $False
}
break
}
}
if ($SoftwareNameTestItemExists -eq $False) {
$DetectionSuccessful = $False
break
}
}
}
else {
$DetectionSuccessful = $False
}
if ($DetectionSuccessful) {
Write-Output "Installed"
}
exit 0