Home / Guides / Find failed Windows logons
Find failed Windows logons (event 4625) on all your servers
Somebody typed a wrong password, a service still uses an old one, or something on the internet is guessing at your Remote Desktop port. Windows records every one of those failed logons in the Security log, with the account, where it came from and why it failed, but only on the server that was asked, and only if auditing is turned on. This guide covers how to check that auditing is on, what the fields of event 4625 mean, how to read them on one server and on many with PowerShell, what we saw when we made logons fail on purpose, and where this stops.
Short answer.
Failed logons are event 4625 in the Security log of the computer that was logged on to. It only exists if the
Audit Logon policy audits failures: check with auditpol /get /subcategory:"Logon". Read it with
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625 }, as an administrator or a member of the
Event Log Readers group. The fields that matter are the account name, Logon Type, the source address and
Status and Sub Status (the reason).
To see every server in one table, use the script below. It groups the failures by account, source and reason, so one mistyped password and a thousand guesses look different at a glance.
Step 1: make sure failures are being logged
If failure auditing is off, Windows writes no 4625 events, and a search for them returns nothing, which looks exactly like "no failed logons". Check first, on each server:
# Is failure auditing on for logons? Look for "Failure" or "Success and Failure".
auditpol /get /subcategory:"Logon"
# Turn it on for this computer (run elevated). On many servers use Group Policy instead.
auditpol /set /subcategory:"Logon" /failure:enable
The Group Policy setting is Computer Configuration, Windows Settings, Security Settings, Advanced Audit Policy Configuration, Audit Policies,
Logon/Logoff, Audit Logon. Microsoft's description of it covers failed logon attempts; set it to Failure at least, or
Success and Failure if you also want the successful logons (event 4624). Group Policy is the way to do it on many servers;
auditpol /set changes one computer. Success events can be numerous on a busy server, which is why many sites start with failures only.
\n The event is written on the computer that was logged on to: the file server for a share, the server for a Remote Desktop session, the workstation for a logon at its own screen.\n For a domain account the domain controller also records 4771 (failed Kerberos pre-authentication) or 4776 (NTLM credential check).\n
\nStep 2: what is in a 4625 event
These are the fields to look at; the full list is on the Microsoft Learn page for the event.
| Field | What it tells you |
|---|---|
| Account For Which Logon Failed (account name, domain) | The name that was typed, which can be a name that does not exist. For a local account the "domain" is the computer name. |
| Logon Type | How the logon was attempted (table below). |
| Source Network Address and Workstation Name | The IP address and computer name the attempt came from. For logons on the computer itself the address is empty or a loopback address. |
| Status and Sub Status | The reason, as hexadecimal NTSTATUS codes. When Status is the generic 0xC000006D, Sub Status holds the specific cause. |
| Caller Process Name | The program that asked for the logon, for example winlogon.exe or svchost.exe. |
The logon types you will meet most:
| Type | Name | Usually means |
|---|---|---|
| 2 | Interactive | Someone at the computer's own keyboard. |
| 3 | Network | Access from the network, such as a file share or a remote command. |
| 4 | Batch | A scheduled task or batch process running as a user. |
| 5 | Service | The Service Control Manager starting a service under an account. |
| 10 | RemoteInteractive | Remote Desktop or Terminal Services. |
| 11 | CachedInteractive | A logon checked against credentials stored on the computer, without a domain controller. |
The reasons that matter most (from the Learn page for event 4625):
| Status / Sub Status | Meaning |
|---|---|
0xC0000064 | The user name does not exist. Many of these in a row can be a sign of someone trying names. |
0xC000006A | The user name is right, the password is wrong. |
0xC0000072 | The account is disabled. |
0xC0000234 | The account is locked out. |
0xC0000193 | The account has expired. |
0xC000006F and 0xC0000070 | Outside the allowed logon hours, and from a workstation the account may not use. |
0xC000015B | The account has not been granted this type of logon at this computer (a missing logon right). |
0xC000005E and 0xC0000192 | No logon server was available, and the Netlogon service was not started. These point to infrastructure, not to a person. |
Step 3: read them on one server
-FilterHashtable filters by log, event ID and time on the server, so only matching events come back. The fields are not in the
message text as separate properties; read them from the event's XML, which names each one:
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddHours(-24) } |
ForEach-Object {
$d = @{}
foreach ($n in ([xml]$_.ToXml()).Event.EventData.Data) { $d[$n.Name] = $n.'#text' }
[pscustomobject]@{
Time = $_.TimeCreated
Account = "$($d['TargetDomainName'])\$($d['TargetUserName'])"
LogonType = $d['LogonType']
SourceIp = $d['IpAddress']
Workstation = $d['WorkstationName']
Status = $d['Status']
SubStatus = $d['SubStatus']
}
} | Format-Table -AutoSize
# Another server: add -ComputerName SERVER01 to Get-WinEvent (rights as described under "Many servers").
\n Run it elevated, or as an account in the Event Log Readers group: Microsoft documents that reading the Security log needs the\n Manage auditing and security log right, and the group is the usual way to grant read access without full administrator rights.\n
\nStep 4: many servers, one table
This script reads the 4625 events of every server you list, adds the logon type name and a readable reason, writes all of them to a CSV file, and prints one line for each combination of server, account, source address and reason, with how many times it happened and when it started and ended. A server that cannot be read is reported, not skipped silently.
param(
[string[]]$ComputerName = @('SERVER01', 'SERVER02', 'SERVER03'),
[datetime]$StartTime = (Get-Date).AddHours(-24),
[string]$CsvPath = "$env:USERPROFILE\Desktop\FailedLogons.csv"
)
# Status / SubStatus codes from the Learn page for event 4625 (plus 0xC0000234, the lockout code in its field list).
$reasons = @{
'0xC0000064' = 'User name does not exist'
'0xC000006A' = 'Wrong password'
'0xC000006D' = 'Bad user name or authentication information'
'0xC000006F' = 'Outside authorized hours'
'0xC0000070' = 'Not allowed from this workstation'
'0xC0000072' = 'Account disabled'
'0xC0000193' = 'Account expired'
'0xC0000234' = 'Account locked out'
'0xC000015B' = 'Logon right not granted'
'0xC000005E' = 'No logon server available'
'0xC0000192' = 'Netlogon service not started'
'0xC0000413' = 'Blocked by an authentication firewall'
}
$logonTypes = @{
2 = 'Interactive'; 3 = 'Network'; 4 = 'Batch'; 5 = 'Service'; 7 = 'Unlock'
8 = 'NetworkCleartext'; 9 = 'NewCredentials'; 10 = 'RemoteInteractive'; 11 = 'CachedInteractive'
}
$filter = @{ LogName = 'Security'; Id = 4625; StartTime = $StartTime }
$found = [System.Collections.Generic.List[object]]::new()
$failed = [System.Collections.Generic.List[object]]::new()
foreach ($computer in $ComputerName) {
try {
$events = Get-WinEvent -ComputerName $computer -FilterHashtable $filter -ErrorAction Stop
}
catch {
# "No events were found" is an error in Get-WinEvent; here it just means nothing failed.
if ($_.FullyQualifiedErrorId -like 'NoMatchingEventsFound*') { continue }
$failed.Add([pscustomobject]@{ Computer = $computer; Error = $_.Exception.Message })
continue
}
foreach ($e in $events) {
$d = @{}
foreach ($n in ([xml]$e.ToXml()).Event.EventData.Data) { $d[$n.Name] = $n.'#text' }
# SubStatus carries the specific reason when Status is the generic 0xC000006D.
$code = if ($d['SubStatus'] -and $d['SubStatus'] -ne '0x0') { $d['SubStatus'] } else { $d['Status'] }
$code = "0x{0:X8}" -f [Convert]::ToUInt32($code.Substring(2), 16)
$type = [int]$d['LogonType']
$found.Add([pscustomobject]@{
Time = $e.TimeCreated
Computer = $computer
Account = if ($d['TargetDomainName'] -and $d['TargetDomainName'] -ne '-') { "$($d['TargetDomainName'])\$($d['TargetUserName'])" } else { $d['TargetUserName'] }
LogonType = if ($logonTypes.ContainsKey($type)) { "$type $($logonTypes[$type])" } else { "$type" }
SourceIp = $d['IpAddress']
Workstation = $d['WorkstationName']
Process = $d['ProcessName']
Status = $code
Reason = if ($reasons.ContainsKey($code)) { $reasons[$code] } else { 'See NTSTATUS values' }
})
}
}
$found | Sort-Object Time -Descending | Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8
# One line per computer, account, source and reason: how often, first and last time.
$found | Group-Object Computer, Account, SourceIp, Reason | ForEach-Object {
$times = $_.Group | Sort-Object Time
[pscustomobject]@{
Computer = $_.Group[0].Computer
Account = $_.Group[0].Account
SourceIp = $_.Group[0].SourceIp
Reason = $_.Group[0].Reason
Count = $_.Count
First = $times[0].Time
Last = $times[-1].Time
}
} | Sort-Object Count -Descending | Format-Table -AutoSize
"{0} failed logons from {1} computers ({2} could not be read) written to {3}" -f $found.Count, $ComputerName.Count, $failed.Count, $CsvPath
foreach ($f in $failed) { Write-Warning "$($f.Computer): $($f.Error)" }
Save it as C:\Scripts\Get-FailedLogons.ps1 and run it with your own server names:
C:\Scripts\Get-FailedLogons.ps1 -ComputerName WEB01, WEB02, RDS01 -StartTime (Get-Date).AddHours(-6)
# Servers from a file (one name per line), the last three days:
C:\Scripts\Get-FailedLogons.ps1 -ComputerName (Get-Content C:\Scripts\servers.txt) -StartTime (Get-Date).AddDays(-3)
-ComputerName: the servers to read.-StartTime: how far back to look (default 24 hours).-CsvPath: where the full list goes.
Tested on Windows PowerShell 5.1 on a Windows 11 test machine (build 26300) with failure auditing switched on, reading the computer by its own
name and as localhost. We made logons fail with test accounts: a wrong password (as a network and as an interactive logon), a user
name that does not exist and a disabled account. The script returned the reasons "Wrong password" (0xC000006A), "User name does not
exist" (0xC0000064) and "Account disabled" (0xC0000072) with the right logon types, in the table and in the CSV; a time
window with no failures gave an empty result and no error; an unreachable computer was reported as a warning ("The RPC server is unavailable") and
counted in the summary. Those failures all happened on the test machine itself, so the source address was empty; we did not test failures that
arrive from another computer. Reading other servers is from Microsoft's documentation and was not tested.
Get-WinEvent -ComputerName reads over RPC, not PowerShell remoting. Each server needs your account in its Event Log Readers
group (or Administrators) and its Remote Event Log Management firewall rules turned on. The permissions, the firewall commands and
the common errors are in
Search Windows Event Logs on multiple servers at once.
Reading the result
- One account, a few failures, then none: a mistyped or newly changed password. Nothing to do.
- One account, steady failures, logon type 4 or 5, from the server itself: a scheduled task or service that still uses an old password. Fix the stored password.
- One source address, many different account names, mostly "User name does not exist", logon type 3 or 10: someone trying names. If the server is reachable from the internet, close the port or put it behind a VPN or gateway.
- One account, failures from many source addresses: someone trying passwords for a name they know. Check whether the account is locked out and whether a later logon from the same address succeeded (event 4624).
- Reasons 0xC000005E or 0xC0000192: look at the domain controller and the Netlogon service on the server, not at the user.
These are patterns, not verdicts: the source address can be a gateway or NAT device that hides the real computer.
Common problems
- The result is empty and you expected failures. Two causes, and the second is easy to miss. Failure auditing may be off (Step 1).
Or your account may not be allowed to read the Security log: on our test machine a standard user outside Event Log Readers got
"No events were found that match the specified selection criteria" from the filtered query, the same message as a log with no matches, while
reading the log without an event ID filter said "Attempted to perform an unauthorized operation." and the same user inside the group read the events.
When in doubt, run
Get-WinEvent -LogName Security -MaxEvents 1as the same account. - The failures you want are gone. The Security log is limited in size and, on a busy server, can fill quickly; when it is full the oldest events are overwritten. The script keeps nothing between runs.
- The source address is empty or a dash. The logon was local, or the attempt did not carry an address. Use the workstation name and the process name instead.
Where doing it by hand stops
- Only what is still in the log, on the servers you listed. A server that is not in the list is not checked, and the Security log keeps little history on a busy one.
- A search, not an alarm. Nothing tells you when failures start; somebody has to run the script again.
- Only the server's view. The domain controller's own events (4771, 4776) are a separate search on different computers.
Questions
What is event 4625 in Windows?
"An account failed to log on." It is written to the Security log of the computer where the logon was attempted, for any failed logon, on domain controllers, member servers and workstations. It names the account, the logon type, where the attempt came from and the reason.
Why is there no event 4625 on my server?
Either failure auditing for the Audit Logon policy is off (check with auditpol /get /subcategory:"Logon"), or the account you read the log with is not allowed to read the Security log and the filtered query comes back with "No events were found". Check both before you conclude that nothing failed.
What do logon types 3 and 10 mean in a failed logon?
Type 3 is a network logon, such as a file share or a remote command, and type 10 is Remote Desktop (RemoteInteractive). Many failures of type 10 from one address on a server that is reachable from the internet usually mean someone is guessing passwords.
How can I tell a mistyped password from an attack?
Look at the pattern, not at one event. A mistyped password is a few failures for one account that stop. Many failures within minutes, from one address with many different account names (mostly "User name does not exist", 0xC0000064), or for one account from many addresses, point to guessing. The events cannot prove who is behind them.
How do I find where a failed logon came from?
The Source Network Address and Workstation Name fields of the 4625 event on the server that was accessed. For logons on the computer itself they are empty or a loopback address. For a domain account, the domain controller also logs 4771 (Kerberos) or 4776 (NTLM), which names the computer the request came from. A gateway or NAT device can hide the real client.
Related
- Search Windows Event Logs on multiple servers at once
- Find failed SQL Server logins (error 18456) on all your servers
- LogTrawler: all your server logs in one searchable place
- All guides
Sources (Microsoft Learn): Event 4625: An account failed to log on, Audit Logon, Event 4771: Kerberos pre-authentication failed, Event 4776: credential validation, auditpol get, auditpol set, Get-WinEvent, Event Logging Security, NTSTATUS values.