Here is the script I used to check any Error message showing on SQL Server’s log.
[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | out-null
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$computers = get-content “DBServers.txt”
$OutFile = “DBErrorLog.txt”
$Line = “Production Databases Error Logs”
$Line | out-file $OutFile
foreach ($computer in $computers)
{
$Line = “r
n———————————–”
$Line | out-file $OutFile -append
$Line = “Working on “ + $computer
write-host $Line
$Server = new-object (“Microsoft.SqlServer.Management.Smo.Server”) “$computer”
$Line = “Server :” + $computer + “ (Version: “ + $Server.Information.VersionString + “)r
n———————————–”
$Line | out-file $OutFile -append
$Line = “[Log Errors]”
$Line | out-file $OutFile -append
$Server.ReadErrorLog().select(“Text like ‘%Error:%’ or Text like ‘%failed%’”, “LogDate Desc”) `
| Format-Table -auto | Out-File $OutFile -append
}
write-host “Output File Created: .” $Outfile