I received a script that is supposed to scan the event logs of 4 DCs, searching the event ID 4740 (user lockout). This is script number 1. Now I thought to myself, "Why scan all the DCs when I can scan the log of the DC that runs the role PDC Emulator?" So I found another script that does about the same job only faster... Now I have 4 questions:
- Does the PDCe have its own log or is it the "general" DC log?
- Do both scripts refer the same source?
- Why does the first one take about an hour and the second takes about 15 seconds?
- Why does the second script give output for only 8 hours back?
First script:
$DD = get-date -format d
$DD
$L = get-eventlog -logname security -computername dc1, dc2, dc3, dc4 -after $DD | where {$_.eventid -eq 4740 } | ft -autosize timegenerated.replacementstrings
$L
$L >> locked.accounts.txt
Second script:
$PDC = Get-ADDomainController -Discover -Service PrimaryDC
Get-WinEvent -ComputerName $PDC -Logname Security -FilterXPath "*[System[EventID=4740 and TimeCreated[timediff(@SystemTime) <= 604800000]] and
EventData]" |
Select-Object TimeCreated,@{Name='User Name';Expression={$_.Properties[0].Value}},@{Name='Source Host';Expression={$_.Properties[1].Value}}