How to see all the application errors related to SQL Server and export them to a .csv file? Just use below command:
Get-EventLog -LogName "Application" -computername RemoteServerName | Where-Object{$_.Source -like "*SQL*"} | Where-Object {$_.EntryType -eq "Error"} | Export-Csv D:\RemoteServerName.csv
xml file:
Get-EventLog -LogName "Application" -computername RemoteServerName | Where-Object{$_.Source -like "*SQL*"} | Where-Object {$_.EntryType -eq "Error"} | Export-Clixml D:\RemoteServerName.xml
txt file:
Get-EventLog -LogName "Application" -computername RemoteServerName | Where-Object{$_.Source -like "*SQL*"} | Where-Object {$_.EntryType -eq "Error"} | Out-File D:\DBS1_sqlevents.txt
To see all SQL Server–related errors on the local or remote server:
Get-EventLog -LogName "Application" -computername PowerServer3 | Where-Object{$_.Source -like "*SQL*"} | Where-Object {$_.EntryType -eq "Error"}
Get-EventLog -LogName "Application" | Where-Object {$_.EntryType -eq "Error"} | Where-Object {($_.TimeGenerated -gt "2012/03/11") -and ($_.TimeGenerated -lt "2012/03/15")} | Sort-Object TimeGenerated -descending | Format-Table -auto
Get-EventLog -ComputerName RemoteServerName -LogName "Application" | Where-Object {$_.EntryType -eq "Error"} | Where-Object {($_.TimeGenerated -gt "20012/03/01") -and ($_.TimeGenerated -lt "2012/03/31")} | Sort-Object TimeGenerated -descending | Format-Table –auto