PowerShell Genie

Investigate account lockouts

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Query Security event ID 4740 from the last eight hours. Inspect the timestamp, logging computer, and message for account-lockout evidence.

The script

1PS> Get-WinEvent -FilterHashtable @{LogName= "Security";Id= 4740;StartTime=(Get-Date).AddHours(- 8)} | Select-Object TimeCreated,MachineName,Message

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 TimeCreated MachineName Message
    2 ----------- ----------- -------
    3 9/10/2026 10:51:12 PM SRV01 Representative event message
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-WinEvent -FilterHashtable @{LogName= "Security";Id= 4740;StartTime=(Get-Date).AddHours(- 8)} | Select-Object TimeCreated,MachineName,Message
    1. Stage 1Get-WinEvent-FilterHashtable
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      A filter hashtable pulls event ID 4740 from the Security log across the last eight hours, and the projection keeps the timestamp, the logging machine, and the message body where the locked account and the originating computer are both recorded.

      Adapting it

      Extend the AddHours value when the lockouts happen overnight, and pass -ComputerName pointing at the PDC emulator so the query reaches the log that actually holds these records.

      Requirements

      Rights to read the Security log on a domain controller.

      If the result is unexpected

      An account-lockout investigation identifies no source machine.

      Relevant events may be on a different controller, outside retention or missing useful caller fields.

      1. Locate the lockout event on the relevant controllers and correlate timestamps with authentication failures.

      Validate the result

      The evidence ties the account, time and suspected source together without inferring a source from a blank field.

      Keep the check reliable

      Collect logs promptly and retain controller names with each event.

      Primary documentation

      Get-WinEvent reference

      Continue
      Genie guideInvestigate account lockouts

      Query Security event ID 4740 from the last eight hours. Inspect the timestamp, logging computer, and message for account-lockout evidence.