Skip to content

Commit 9fd3aee

Browse files
committed
Added Get-ApplockerWinEvent function.
1 parent 51b3bf8 commit 9fd3aee

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed

Functions/Find-NthIndexOf.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
System.Int
3737
the occurrence of the character to find.
3838
.Parameter IgnoreCase
39+
System.Management.Automation.SwitchParameter
3940
Preforms a case insensitive regex match.
4041
.Example
4142
PS C:\> Find-NthIndexOf -Target "CN=me,OU=Users,DC=domain,DC=org" -Value "=" -Nth 2

Functions/Get-ApplockerWinEvent.ps1

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<#PSScriptInfo
2+
3+
.Version
4+
1.0
5+
.Guid
6+
9be00d5e-0fd8-4b87-be0a-28e97bdd67b7
7+
.Author
8+
Thomas J. Malkewitz @dotps1
9+
.Tags
10+
Applocker, WinEvent
11+
.ProjectUri
12+
https://github.com/dotps1/PSFunctions
13+
14+
#>
15+
16+
<#
17+
18+
.Synopsis
19+
Gets Applocker related events.
20+
.Description
21+
Gets Applocker events based on given critera from the local or remote machine(s).
22+
.Inputs
23+
System.String
24+
.Outputs
25+
System.Diagnostics.Eventing.Reader.EventLogRecord
26+
.Parameter Name
27+
System.String
28+
The name of the system to get Applocker data against.
29+
.Parameter EventType
30+
System.String
31+
The type of Applocker events to get, the default value is all events from the Microsoft-Windows-AppLocker log provider.
32+
.Parameter LogName
33+
System.String
34+
The specific log to pull events from, the default value is all logs from the Microsoft-Windows-AppLocker log provider.
35+
.Parameter Credential
36+
System.Management.Automation.PSCredential
37+
Credential object used for authentication.
38+
.Parameter MaxEvents
39+
System.Int
40+
The maximum number of EventLogRecord objects to return.
41+
.Parameter Oldest
42+
System.Management.Automation.SwitchParameter
43+
Returns EventLogRecord objects from oldest to newest.
44+
.Parameter StartTime
45+
System.DateTime
46+
The starting range to get EventLogRecord objects from.
47+
.Parameter EndTime
48+
System.DateTime
49+
The ending range to get EventLogRecord objects from.
50+
.Example
51+
PS C:\> Get-ApplockerWinEvent -MaxEvents 2
52+
53+
54+
ProviderName: Microsoft-Windows-AppLocker
55+
56+
TimeCreated Id LevelDisplayName Message
57+
----------- -- ---------------- -------
58+
10/5/2017 8:17:59 AM 8005 Information %OSDRIVE%\USERS\dotps1\DOCUMENTS\GITHUB\PSFUNCTIONS\FUNCTIONS\GET-APPLOCKERWINEVENT.PS1 was allowed to run.
59+
10/5/2017 8:15:10 AM 8002 Information %PROGRAMFILES%\GIT\MINGW64\BIN\GIT.EXE was allowed to run.
60+
.Example
61+
PS C:\> Get-ApplockerWinEvent -MaxEvents 2 -Oldest -LogName ExeAndDll -Credential (Get-Credential) -ComputerName myremotebox
62+
63+
64+
ProviderName: Microsoft-Windows-AppLocker
65+
66+
TimeCreated Id LevelDisplayName Message
67+
----------- -- ---------------- -------
68+
10/5/2017 7:33:43 AM 8002 Information %OSDRIVE%\USERS\dotps1\APPDATA\LOCAL\MICROSOFT\ONEDRIVE\ONEDRIVESTANDALONEUPDATER.EXE was prevented from running.
69+
10/5/2017 7:33:43 AM 8002 Information %PROGRAMFILES%\GIT\CMD\GIT.EXE was allowed to run.
70+
.Notes
71+
When running against a remote machine, and the results are: "No events were found that match the specified selection criteria.", you may just need to authenticate.
72+
Run the command and use the -Credential parameter.
73+
.Link
74+
https://dotps1.github.io
75+
.Link
76+
https://www.powershellgallery.com/packages/Get-ApplockerWinEvent
77+
.Link
78+
https://grposh.github.io
79+
80+
#>
81+
82+
83+
[CmdletBinding()]
84+
[OutputType(
85+
[System.Diagnostics.Eventing.Reader.EventLogRecord]
86+
)]
87+
88+
param(
89+
[Parameter(
90+
ValueFromPipeline = $true
91+
)]
92+
[Alias(
93+
"ComputerName"
94+
)]
95+
[String[]]
96+
$Name = $env:COMPUTERNAME,
97+
98+
[Parameter()]
99+
[ValidateSet(
100+
"All", "Allowed", "Audit", "Blocked"
101+
)]
102+
[String]
103+
$EventType = "All",
104+
105+
[Parameter()]
106+
[ValidateSet(
107+
"ExeAndDll", "MsiAndScript", "PackagedAppExecution", "PackagedAppDeployment"
108+
)]
109+
[String]
110+
$LogName,
111+
112+
[Parameter()]
113+
[PSCredential]
114+
$Credential = [PSCredential]::Empty,
115+
116+
[Parameter()]
117+
[Int]
118+
$MaxEvents,
119+
120+
[Parameter()]
121+
[Switch]
122+
$Oldest,
123+
124+
[Parameter()]
125+
[DateTime]
126+
$StartTime = [DateTime]::MinValue,
127+
128+
[Parameter()]
129+
[DateTime]
130+
$EndTime = [DateTime]::MaxValue
131+
)
132+
133+
begin {
134+
$filterHashTable = @{
135+
ProviderName = "Microsoft-Windows-AppLocker"
136+
StartTime = $StartTime
137+
EndTime = $EndTime
138+
}
139+
140+
switch ($EventType) {
141+
"Allowed" {
142+
$filterHashTable.Add(
143+
"Id", @(
144+
8002, 8005, 8020, 8023
145+
)
146+
)
147+
}
148+
149+
"Audit" {
150+
$filterHashTable.Add(
151+
"Id", @(
152+
8003, 8006, 8021, 8024
153+
)
154+
)
155+
}
156+
157+
"Blocked" {
158+
$filterHashTable.Add(
159+
"Id", @(
160+
8004, 8007, 8022, 8025
161+
)
162+
)
163+
}
164+
}
165+
166+
switch ($LogName) {
167+
"ExeAndDll" {
168+
$filterHashTable.Add(
169+
"LogName", "Microsoft-Windows-AppLocker/EXE and DLL"
170+
)
171+
}
172+
173+
"MsiAndScript" {
174+
$filterHashTable.Add(
175+
"LogName", "Microsoft-Windows-AppLocker/MSI and Script"
176+
)
177+
}
178+
179+
"PackagedAppExecution" {
180+
$filterHashTable.Add(
181+
"LogName", "Microsoft-Windows-AppLocker/Packaged app-Execution"
182+
)
183+
}
184+
185+
"PackagedAppDeployment" {
186+
$filterHashTable.Add(
187+
"LogName", "Microsoft-Windows-AppLocker/Packaged app-Deployment"
188+
)
189+
}
190+
}
191+
}
192+
193+
process {
194+
foreach ($nameValue in $Name) {
195+
$getWinEventParameters = @{
196+
ComputerName = $nameValue
197+
Credential = $Credential
198+
FilterHashTable = $filterHashTable
199+
ErrorAction = "Stop"
200+
}
201+
202+
if ($MaxEvents -gt 0) {
203+
$getWinEventParameters.Add(
204+
"MaxEvents", $MaxEvents
205+
)
206+
}
207+
208+
if ($Oldest.IsPresent) {
209+
$getWinEventParameters.Add(
210+
"Oldest", $Oldest
211+
)
212+
}
213+
214+
try {
215+
$output = Get-WinEvent @getWinEventParameters
216+
217+
Write-Output -InputObject $output
218+
} catch {
219+
$PSCmdlet.ThrowTerminatingError(
220+
$_
221+
)
222+
}
223+
}
224+
}

0 commit comments

Comments
 (0)