Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevin-Bronsdijk/24933bf7632c84005407 to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/24933bf7632c84005407 to your computer and use it in GitHub Desktop.
monitoring-failed-sql-server-login-requests
Import-Module SQLPS -DisableNameChecking
#replace your with your instance name
$instanceName = "server\instance";
$srv = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName;
$srv.ReadErrorLog() |
Where ProcessInfo -like "*Logon*" |
Where Text -like "*Login failed for*" |
Format-List
$srv.ReadErrorLog() |
Where { ($_.LogDate.Date -eq (Get-Date).Date) -and ($_.ProcessInfo -like "*Logon*") -and ($_.Text -like "*Login failed for*")} |
Group Text | Where { ($_.Count -gt 5)}|Sort count -Descending | Format-Table Count, Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment