Jun 11, 2026, 1:19 PM
This commit is contained in:
@@ -123,4 +123,30 @@ GROUP BY d.name, d.state_desc, d.recovery_model_desc
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Import-DBAToolBoxDependencies, Test-SQLConnection, Get-SQLDatabases
|
||||
function Get-SQLErrors {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets SQL Server error log entries for the last hour using Get-DbaErrorLog.
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$ServerInstance
|
||||
)
|
||||
|
||||
try {
|
||||
# Calculate time (1 hour ago)
|
||||
$afterTime = (Get-Date).AddHours(-1)
|
||||
$afterString = $afterTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
# Call dbatools cmdlet to fetch log entries
|
||||
$logs = Get-DbaErrorLog -SqlInstance $ServerInstance -After $afterString -LogNumber 0 -ErrorAction Stop
|
||||
|
||||
# Clean select properties
|
||||
$result = $logs | Select-Object LogDate, Source, Text
|
||||
return $result
|
||||
} catch {
|
||||
throw "Failed to fetch SQL error log: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Import-DBAToolBoxDependencies, Test-SQLConnection, Get-SQLDatabases, Get-SQLErrors
|
||||
Reference in New Issue
Block a user