dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Get-DbaSqlLog

Gets the “SQL Error Log” of an instance. Returns all 10 error logs by default.

Screenshots

dbatools - Get-DbaSqlLog

Examples

Returns every log entry from sql01\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint

Returns all log entries for log number 3 and 6 on sql01\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint -LogNumber 3, 6

Returns every log entry, with a source of Logon, from sql01\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint -Source Logon

Returns every log entry for log number 3, with “login failed” in the text, from sql01\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint -LogNumber 3 -Text “login failed”

Returns the most recent SQL Server error logs for “sql2014″,”sql2016” and “sqlcluster\sharepoint”

$servers = “sql2014″,”sql2016”, “sqlcluster\sharepoint”
$servers | Get-DbaSqlLog -LogNumber 0

Returns every log entry found after the date 11/14/2006 00:00 from sql101\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint -After ’11/14/2006 00:00′

Returns every log entry found before the date 08/16/2016 00:00 from sql101\sharepoint SQL Server instance.

Get-DbaSqlLog -SqlInstance sql01\sharepoint -Before ’08/16/2016 00:00′

Author

This command was created by Chrissy LeMaire. You can find Chrissy on Twitter.

Get-Help

From PowerShell, execute Get-Help Get-DbaSqlLog -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaSqlLog.ps1 on GitHub
 

Related commands