-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ADUserLockouts.ps1
executable file
·48 lines (48 loc) · 1.49 KB
/
Get-ADUserLockouts.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
Function Get-ADUserLockouts {
[CmdletBinding(
DefaultParameterSetName = 'All'
)]
param (
[Parameter(
ValueFromPipeline = $true,
ParameterSetName = 'ByUser'
)]
[Microsoft.ActiveDirectory.Management.ADUser]$Identity
,
[datetime]$StartTime
,
[datetime]$EndTime
)
Begin{
$filterHt = @{
LogName = 'Security'
ID = 4740
}
if ($PSBoundParameters.ContainsKey('StartTime')){
$filterHt['StartTime'] = $StartTime
}
if ($PSBoundParameters.ContainsKey('EndTime')){
$filterHt['EndTime'] = $EndTime
}
$PDCEmulator = (Get-ADDomain).PDCEmulator
# Query the event log just once instead of for each user if using the pipeline
$events = Get-WinEvent -ComputerName $PDCEmulator -FilterHashtable $filterHt
}
Process {
if ($PSCmdlet.ParameterSetName -eq 'ByUser'){
$user = Get-ADUser $Identity
# Filter the events
$output = $events | Where-Object {$_.Properties[0].Value -eq $user.SamAccountName}
} else {
$output = $events
}
foreach ($event in $output){
[pscustomobject]@{
UserName = $event.Properties[0].Value
CallerComputer = $event.Properties[1].Value
TimeStamp = $event.TimeCreated
}
}
}
End{}
}