Excessive Logon Attempts
Overview
Counts the failed logon attempts (Security event ID 4625) recorded since the last run and raises an alert when the count reaches the threshold, which can indicate a brute-force or password-spraying attack. The count is a total for the device across all users, taken after the configured exclusions. Batch and service logons, and a computer account failing from its own workstation, are never counted.
Whenever any failed logons are counted, the activity details list them grouped by user, domain and source IP address, along with the workstation, logon type, failure status and logon process. The script saves the time each run started in cPVAL Excessive Logon LastRunTime, so the next run starts where this one ended. It does not change anything else on the device.
The automation is the evaluation script of the Monitor - Excessive Logon Attempts compound condition in the Excessive Logon Attempts solution.
The first run, and any run where cPVAL Excessive Logon LastRunTime is empty or invalid, checks the last 60 minutes.
Requirements
- Windows. The compound condition runs it only on domain controllers whose cPVAL Roles Detected field contains
Infrastructure Master. - Run As:
System - PowerShell 5.1
- Logon failure auditing enabled, so Windows records event ID 4625. Windows Server enables it by default.
Sample Run

Parameters
Every parameter is optional. A parameter left empty uses the matching custom field, so leave them empty in the compound condition and set the values in the custom fields at the organization, location or device level. A value entered in a parameter replaces the custom field value for that run rather than adding to it.
List entries can be separated by commas or semicolons. Matching is not case-sensitive, and every entry accepts the wildcards * (any number of characters) and ? (exactly one character).
| Name | Example | Accepted Values | Required | Default | Type | Description |
|---|---|---|---|---|---|---|
| Threshold | 20 | A whole number greater than 0 | False | Empty, which uses cPVAL Excessive Logon Threshold, or 10 when that is empty too | String | Number of failed logons since the last run that raises the alert. The alert is raised when the count is equal to or greater than this value. The count is a total across all users, after exclusions. 0, a negative number or text that is not a number uses 10. |
| ExcludeUsers | scanner; svc_*; *$ | Usernames | False | Empty, which uses cPVAL Excessive Logon ExcludeUsers | String | Usernames to ignore on every computer and in every domain. *$ ignores all computer (machine) accounts. |
| ExcludeByComputer | FRONTDESK-01/reception; LAB-PC07/* | COMPUTER/account entries. A backslash also works. | False | Empty, which uses cPVAL Excessive Logon ExcludeByComputer | String | Accounts to ignore when the computer in the entry is the Domain or the WorkstationName of the failed logon. * as the account matches every account. |
| ExcludeByDomain | CONTOSO/svc_scan; FABRIKAM/* | DOMAIN/account entries. A backslash also works. | False | Empty, which uses cPVAL Excessive Logon ExcludeByDomain | String | Accounts to ignore only when they belong to the domain in the entry. For a local account, the domain is the computer name. * as the account matches every account. |
| ExcludeByWorkstation | COPIER-2F/scan2folder; TRAINING-*/* | WORKSTATION/account entries. A backslash also works. | False | Empty, which uses cPVAL Excessive Logon ExcludeByWorkstation | String | Accounts to ignore only when the attempt comes from the workstation in the entry. * as the account matches every account. |
| ExcludeLogonProcess | CHAP; Advapi; Seclogo | Logon process names, such as CHAP, Advapi, Seclogo or Kerberos | False | Empty, which uses cPVAL Excessive Logon ExcludeLogonProcess | String | Logon process names to ignore everywhere. Avoid NtLmSsp and User32, which would hide most password-guessing attacks. |
Custom Fields
| Custom Field | Scope | Type | Description |
|---|---|---|---|
| cPVAL Enable Excessive Logon Detection | Organization, Location, Device | Drop-down | Read by the compound condition, not by the script. Disable stops the condition from running the automation on the device. Empty works like Enable. |
| cPVAL Excessive Logon Threshold | Organization, Location, Device | Text | Number of failed logons that raises the alert. Used when the Threshold parameter is empty. Empty uses 10. |
| cPVAL Excessive Logon ExcludeUsers | Organization, Location, Device | Multi-line | Usernames to ignore everywhere. Used when the ExcludeUsers parameter is empty. |
| cPVAL Excessive Logon ExcludeByComputer | Organization, Location, Device | Multi-line | COMPUTER\account entries to ignore on or from one computer. Used when the ExcludeByComputer parameter is empty. |
| cPVAL Excessive Logon ExcludeByDomain | Organization, Location, Device | Multi-line | DOMAIN\account entries to ignore in one domain. Used when the ExcludeByDomain parameter is empty. |
| cPVAL Excessive Logon ExcludeByWorkstation | Organization, Location, Device | Multi-line | WORKSTATION\account entries to ignore from one workstation. Used when the ExcludeByWorkstation parameter is empty. |
| cPVAL Excessive Logon ExcludeLogonProcess | Organization, Location, Device | Text | Logon process names to ignore everywhere. Used when the ExcludeLogonProcess parameter is empty. |
| cPVAL Excessive Logon LastRunTime | Device | Text | Time the script last ran, read and written by the script on every run that reads the Security log. The next run counts failed logons from this time onward. Does not need to be filled in manually. |
Dependencies
- Solution: Excessive Logon Attempts
- Condition: Excessive Logon Attempts
- CW Manage Ticket Template: Excessive Logon Failures
- Custom Field: cPVAL Roles Detected
- Custom Field: cPVAL Enable Excessive Logon Detection
- Custom Field: cPVAL Excessive Logon Threshold
- Custom Field: cPVAL Excessive Logon ExcludeUsers
- Custom Field: cPVAL Excessive Logon ExcludeByComputer
- Custom Field: cPVAL Excessive Logon ExcludeByDomain
- Custom Field: cPVAL Excessive Logon ExcludeByWorkstation
- Custom Field: cPVAL Excessive Logon ExcludeLogonProcess
- Custom Field: cPVAL Excessive Logon LastRunTime
Automation Setup/Import
Output
- Activity Details
- Custom Field: cPVAL Excessive Logon LastRunTime
Changelog
2026-11-11
- Updated the document to the current automation documentation standard.
- Removed the
Minutesparameter. The script now counts the failed logons recorded since its last run, saved in cPVAL Excessive Logon LastRunTime, and checks the last 60 minutes when no last run time is saved. - Made
Thresholdoptional. When it is empty, the script uses cPVAL Excessive Logon Threshold, or10when that is empty too. - Added the
ExcludeUsers,ExcludeByComputer,ExcludeByDomain,ExcludeByWorkstationandExcludeLogonProcessparameters and their custom fields.
2025-08-14
- Fixed the bug in the script that triggered the alert only after 2 Failed Logon attempts
2025-07-07
- Initial version of the document