Configuring SQL Server Audit
In this recipe, we will set up SQL Server Audit to track failed logins.
How to do it...
These are the steps required to configure and test SQL Server Audit:
- 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 $instanceName = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
- Use the following script to first create SQL Server Audit that uses a file destination:
$auditName = "FileAudit" #if it exists, disable then drop if($server.Audits[$auditName]) { $server.Audits[$auditName].Disable() $server.Audits[$auditName].Drop() } $serverAudit = ...
Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.