· Uwe Janke
Commands / Get-sqmErrorLog

Get-sqmErrorLog

DiagnosticssqmSQLTool v1.9.114+ · Get🔓 VIEW SERVER STATE (xp_readerrorlog)
Wraps dbatools' 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

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEOne or more instances. Pipeline-capable.
-SqlCredentialPSCredentialOptional, SQL or Windows credential.
-LogNumberint[]Optional@(0)0 = current log, 1 = Errorlog.1, etc. Accepts multiple values to sweep several logs in one call.
-FailedLoginsswitchSwitch$falseOnly error 18456, language-neutral detection.
-SuccessfulLoginsswitchSwitch$falseOnly 18453/18454, language-neutral detection.
-LoginsswitchSwitch$falseShorthand for -FailedLogins -SuccessfulLogins together.
-Backups / -RestoresswitchSwitch$falseEnglish text match ("Database backed up.", "Restore is complete on database ...").
-ErrorsswitchSwitch$falseThe "Error: n, Severity: n, State: n." format.
-Shutdowns / -StartupsswitchSwitch$false-Startups is verbose by design, one line per database on every service start.
-CorruptionEvents / -IOErrors / -MemoryPressure / -ServiceBrokerEventsswitchSwitch$falseEnglish text match against known message phrasing.
-Patternstring[]Optional, Freeform regex, case-insensitive. Combines with any switch (AND), or works standalone.
-Databasestring[]Optional, Only entries whose text mentions one of these database names.
-Since / -BeforedatetimeOptional, Passed through to Get-DbaErrorLog's own -After/-Before.
-TopintOptional0Most recent N entries per instance. 0 = unlimited.
-OutputPathstringOptionalGet-sqmDefaultOutputPath\ErrorLogCSV/HTML report directory. Set to $null/empty to skip export.
-ContinueOnErrorswitchSwitch$falseContinue with the next instance on error.
-EnableExceptionswitchSwitch$falseThrow exceptions immediately.
-NoOpenswitchSwitch$falseDo not automatically open the generated HTML report.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES foreach $instance in $SqlInstance Language-neutral login regex from sys.messages 18456 (failed) / 18453+18454 (success) → ConvertTo-sqmMessageRegex, every installed language tried foreach -LogNumber: Get-DbaErrorLog (+ -Since/-Before) A missing archive number logs a WARNING, does not abort the instance Categorize each row (first match wins) FailedLogin / SuccessfulLogin, via the language-neutral regex above Backup, Restore, Error, Shutdown, Startup, Corruption, IOError, Memory, ServiceBroker Error category also extracts ErrorNumber/Severity/State via regex groups No match → Category = "Other" (still returned, still labeled) Category text patterns are English; use -Pattern for a localized instance Apply filters in order (each narrows the previous result) 1. Category switches (if any set) → 2. -Database (OR across values) 3. -Pattern (OR across values, ANDed with the above) No category switch set → every entry is kept, still categorized Sort by LogDate descending, apply -Top (repeat for next instance) -OutputPath and results > 0? YES Export CSV + HTML Copy-sqmToCentralPath NO Return [PSCustomObject[]] SqlInstance · LogDate · Category · LoginName · ErrorNumber/Severity/State · Text DONE

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'