-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ADUserBadPasswords.ps1
executable file
·62 lines (62 loc) · 1.99 KB
/
Get-ADUserBadPasswords.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
Function Get-ADUserBadPasswords {
[CmdletBinding(
DefaultParameterSetName = 'All'
)]
Param (
[Parameter(
ValueFromPipeline = $true,
ParameterSetName = 'ByUser'
)]
[Microsoft.ActiveDirectory.Management.ADUser]$Identity
,
[string]$DomainController = (Get-ADDomain).PDCEmulator
,
[datetime]$StartTime
,
[datetime]$EndTime
)
Begin {
$LogonType = @{
'2' = 'Interactive'
'3' = 'Network'
'4' = 'Batch'
'5' = 'Service'
'7' = 'Unlock'
'8' = 'Networkcleartext'
'9' = 'NewCredentials'
'10' = 'RemoteInteractive'
'11' = 'CachedInteractive'
}
$filterHt = @{
LogName = 'Security'
ID = 4625
}
if ($PSBoundParameters.ContainsKey('StartTime')){
$filterHt['StartTime'] = $StartTime
}
if ($PSBoundParameters.ContainsKey('EndTime')){
$filterHt['EndTime'] = $EndTime
}
# Query the event log just once instead of for each user if using the pipeline
$events = Get-WinEvent -ComputerName $DomainController -FilterHashtable $filterHt
}
Process {
if ($PSCmdlet.ParameterSetName -eq 'ByUser'){
$user = Get-ADUser $Identity
# Filter for the user
$output = $events | Where-Object {$_.Properties[5].Value -eq $user.SamAccountName}
} else {
$output = $events
}
foreach ($event in $output){
[pscustomobject]@{
TargetAccount = $event.properties.Value[5]
LogonType = $LogonType["$($event.properties.Value[10])"]
CallingComputer = $event.Properties.Value[13]
IPAddress = $event.Properties.Value[19]
TimeStamp = $event.TimeCreated
}
}
}
End{}
}