dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Get-DbaErrorLogFile

Open pollusb opened this issue 1 year ago • 1 comments

Summarize Command's Functionality

Get-DbaErrorLog does not provide access to errorlog info when the SQL instance is down. This function would return the files (or the content) to diagnose a problem that might have to do with the fact that it's down.

Is there a command that is similiar or close to what you are looking for?

No

Technical Details

No response

pollusb avatar Apr 25 '24 18:04 pollusb

I don't think we can accomodate this as explained in #9330, the api is wildly different. That being said, if the instance is offline, isn't Get-DbaWindowsLog a more valuable candidate ? If not, the only possible way to get at least the path would be Get-DbaStartupParameter, then hoping that it points to a path where the errorlogs are.

niphlod avatar Sep 25 '24 21:09 niphlod

@claude what do you think? close or niph's suggestion?

potatoqualitee avatar Nov 28 '25 16:11 potatoqualitee

Claude finished @potatoqualitee's task —— View job


Analysis Complete

I've examined the three relevant commands and the user's request. Here's my recommendation:

Recommendation: Close the issue

Get-DbaWindowsLog already provides exactly what the user needs.

Detailed Analysis

The Problem:

  • Get-DbaErrorLog uses SMO's $server.ReadErrorLog() method (line 127)
  • Requires an active SQL Server connection
  • Cannot access error logs when the instance is down

The Solution (Already Exists):

Get-DbaWindowsLog is designed specifically for this use case:

  • Reads error log files directly from the file system via remote PowerShell (lines 187-240)
  • Locates log files by querying Windows Application Event Log for SQL Server startup events (Event ID 17111)
  • Parses raw log files into structured objects with timestamps, SPIDs, error numbers, severity, and messages
  • Works when SQL Server is offline - only requires Windows credentials
  • Returns the same type of diagnostic information needed to troubleshoot a down instance

Additional Tool:

Get-DbaStartupParameter can help locate error log files:

  • Uses WMI to read service configuration (works when SQL is down)
  • Returns the error log path in the ErrorLog property (line 164)
  • Useful if you need to know where the files are before accessing them

Example Usage for Down Instance

# When SQL Server is down, use Windows credentials to read error logs
$cred = Get-Credential -Message "Windows credentials"
Get-DbaWindowsLog -SqlInstance SQL01 -Credential $cred

# Find where error logs are located
Get-DbaStartupParameter -SqlInstance SQL01 -Credential $cred -Simple | Select-Object ErrorLog

Why niphlod is correct

niphlod's assessment is spot on - Get-DbaWindowsLog is the appropriate solution for this scenario. Creating a new Get-DbaErrorLogFile command would duplicate existing functionality and create confusion about which command to use.

The issue mentioned (#9330) likely discusses how the SMO API (ReadErrorLog()) is fundamentally different from file system access, which is why we have two separate commands with different approaches.

Suggested Response to User

Close the issue with a helpful message pointing the user to Get-DbaWindowsLog, explaining that:

  1. It already provides file-based error log access when SQL Server is down
  2. It requires Windows credentials instead of SQL credentials
  3. Include the example usage above

claude[bot] avatar Nov 28 '25 16:11 claude[bot]

I also agree. Let's close this !

pollusb avatar Nov 28 '25 18:11 pollusb