Get-sqmErrorLog
DiagnosticssqmSQLTool v1.9.114+ · Get🔓 VIEW SERVER STATE (xp_readerrorlog)
Get-DbaErrorLog with ready-made category filters instead of everyone re-inventing the same -match pattern: -FailedLogins/-SuccessfulLogins (matched language-neutrally via sys.messages templates for 18456/18453/18454, not hardcoded English text), -Backups, -Restores, -Errors, -Shutdowns, -Startups, -CorruptionEvents, -IOErrors, -MemoryPressure, -ServiceBrokerEvents, plus -Database, -Since/-Before, -LogNumber (current log and/or archives), -Top, and a freeform -Pattern escape hatch that combines with any filter or works standalone. Every entry gets a Category label even with no filter applied, and exports to CSV/HTML.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string[] | Optional | $env:COMPUTERNAME | One or more instances. Pipeline-capable. |
| -SqlCredential | PSCredential | Optional | , | SQL or Windows credential. |
| -LogNumber | int[] | Optional | @(0) | 0 = current log, 1 = Errorlog.1, etc. Accepts multiple values to sweep several logs in one call. |
| -FailedLogins | switch | Switch | $false | Only error 18456, language-neutral detection. |
| -SuccessfulLogins | switch | Switch | $false | Only 18453/18454, language-neutral detection. |
| -Logins | switch | Switch | $false | Shorthand for -FailedLogins -SuccessfulLogins together. |
| -Backups / -Restores | switch | Switch | $false | English text match ("Database backed up.", "Restore is complete on database ..."). |
| -Errors | switch | Switch | $false | The "Error: n, Severity: n, State: n." format. |
| -Shutdowns / -Startups | switch | Switch | $false | -Startups is verbose by design, one line per database on every service start. |
| -CorruptionEvents / -IOErrors / -MemoryPressure / -ServiceBrokerEvents | switch | Switch | $false | English text match against known message phrasing. |
| -Pattern | string[] | Optional | , | Freeform regex, case-insensitive. Combines with any switch (AND), or works standalone. |
| -Database | string[] | Optional | , | Only entries whose text mentions one of these database names. |
| -Since / -Before | datetime | Optional | , | Passed through to Get-DbaErrorLog's own -After/-Before. |
| -Top | int | Optional | 0 | Most recent N entries per instance. 0 = unlimited. |
| -OutputPath | string | Optional | Get-sqmDefaultOutputPath\ErrorLog | CSV/HTML report directory. Set to $null/empty to skip export. |
| -ContinueOnError | switch | Switch | $false | Continue with the next instance on error. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately. |
| -NoOpen | switch | Switch | $false | Do not automatically open the generated HTML report. |
Execution Flow
Examples
All failed logins in the last 24 hours
Get-sqmErrorLog -SqlInstance "SQL01" -FailedLogins -Since (Get-Date).AddDays(-1)
The 100 most recent login events, failed and successful
Get-sqmErrorLog -SqlInstance "SQL01" -Logins -Top 100
Backup-completion entries for one database
Get-sqmErrorLog -SqlInstance "SQL01" -Backups -Database "Orders"
Internal SQL Server errors across current log + 2 archives, narrowed by number
Get-sqmErrorLog -SqlInstance "SQL01" -LogNumber 0,1,2 -Errors -Pattern '824|825'