Listing failed login attempts
This recipe lists failed login attempts in your SQL Server instance.
Getting ready
In order to get some entries in this recipe, you will need to simulate some failed login attempts in your SQL Server instance, if you don't already have any previous failed logins. One way to do this is to try logging in to SQL Server using SQL Server Management Studio and providing an incorrect username or password.
How to do it...
To check the failed login attempts, follow these steps:
Open PowerShell ISE as an administrator.
Import the
SQLPS
module and create a new SMO Server Object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run:
#According to MSDN: #ReadErrorLog returns A StringCollection system object #value that contains an enumerated list of errors ...