When the SQL Server Services Started and Stopped in Windows server
<#
Events that occur after stopping services.
#19032:SQL Trace was stopped due to server shutdown. Trace ID
= '1'. This is an informational message only; no user action is required.
#6527.NET Framework runtime has been stopped.
17148.NET Framework runtime has been stopped.
17148SQL Server is terminating in response to a 'stop' request
from Service Control Manager. This is an informational message only. No user
action is required.
102SQLServerAgent service successfully stopped.
15457Configuration option 'Agent XPs' changed from 1 to 0. Run
the RECONFIGURE statement to install.
#>
clear
Get-EventLog -LogName
Application|
Where-Object{$_.EventID -in
(19032,6527,17148,102,15457)}|
Format-Table -AutoSize
Sort-Object Time
-Descending
<#
3408:Recovery is complete. This is an informational message
only. No user action is required.
9688:Service Broker manager has started.
17137:Starting up database 'tempdb'.
17136:Clearing tempdb database.
17137:Starting up database 'model'.
26076:SQL Server is attempting to register a Service Principal
Name (SPN) for the SQL Server service.
Kerberos authentication will not be possible until a SPN is
registered for the SQL Server service.
This is an informational message. No user action is required.
17137:Starting up database 'mssqlsystemresource'.
17126:SQL Server is now ready for client connections. This is
an informational message; no user action is required.
17137:Starting up database 'master'.
#>
clear
Get-EventLog -LogName
Application|
Where-Object{$_.EventID -in
(3408,9688,17137,17136,26076,17126)}|
Format-Table -AutoSize
Sort-Object Time
-Descending
<#
The below piece of code will sent mail
#>
clear
$OutFile='D:\Status\Info.txt'
$EventLogApp=Get-EventLog -LogName
Application|
Where-Object{$_.EventID -in
(17162,17147,101,1074)}
$EventLogApp|
#$EventLog.EventID,$EventLog.Message,$EventLog.UserName,$EventLog.TimeWritten
Select-Object @{Name="TimeWritten";expression={$_.TimeWritten}},
@{Name="EventID";expression={$_.EventiD}},
@{Name="Message";expression={$_.Message}},
@{Name="User";expression={$_.UserName}}|
Sort-Object TimeWritten
-Descending|Out-File $OutFile
#The below piece of code will sent an attachment to your mail.
Send-MailMessage `
-To 'toaddress@mail.com'
`
-Subject 'ServerStatus'
`
-From 'fromaddress@mail.com'
`
#Check the below server in Database mail
-SmtpServer 'SMTPServerIP
or Name here' `
-Attachments $OutFile
#The below command will show you the latest event of each it. However i have handeled SQLServer events. The hours i have handled here for one week
cls
Get-EventLog
-LogName
Application
-After((Get-Date).AddHours(-168))|
Sort-Object
-Descending
-Property
TimeGenerated|
Group-Object
-Property
EventID|ForEach-Object{
$_.Group[0]|
Select-Object
EventID,TimeGenerated,Message
}|Where-Object
{$_.EventID
-in
(17162,17147,101,1074)}|
Format-Table
-AutoSize
#The below eventid's talk about windows server shutdown.
#The below eventid's talk about windows server shutdown.
clear
Get-EventLog -LogName
sYSTEM|
Where-Object{$_.EventID -in (1100,1074)}| Format-Table -AutoSize
| Out-String
-Width 10000 |Sort-Object Time
-Descending
#Getting unique latest and unique windows id's through power shell
cls
$ServerList="C:\ServerList\ServerList.txt"
$OutFile="C:\ServerList\Result.html"
Get-Content $ServerList|
ForEach-Object {
$ComputerName=$_
Invoke-Command `
-ComputerName $ComputerName {
$Filter = @{
Logname = 'Application','System'
ID = 1074,4625
StartTime = [datetime]::Today.AddDays(-50)
EndTime = [datetime]::Today
}
$Command=Get-WinEvent -FilterHashtable $Filter
$Command | Select-Object Machinename,TimeCreated,ID,Message | group ID |
ForEach-Object{$_.Group | sort TimeCreated -Descending | select -First 1}
}
} | ConvertTo-Html > $OutFile
#Getting unique latest and unique windows id's through power shell
cls
$ServerList="C:\ServerList\ServerList.txt"
$OutFile="C:\ServerList\Result.html"
Get-Content $ServerList|
ForEach-Object {
$ComputerName=$_
Invoke-Command `
-ComputerName $ComputerName {
$Filter = @{
Logname = 'Application','System'
ID = 1074,4625
StartTime = [datetime]::Today.AddDays(-50)
EndTime = [datetime]::Today
}
$Command=Get-WinEvent -FilterHashtable $Filter
$Command | Select-Object Machinename,TimeCreated,ID,Message | group ID |
ForEach-Object{$_.Group | sort TimeCreated -Descending | select -First 1}
}
} | ConvertTo-Html > $OutFile
Comments