Summary

The Get-EventLog cmdlet is not specific to Exchange Server, but we can use it to gather information about Exchange Server from the event logs. For example, to return the 10 most recent event log entries that have a source of MSExchange Common. In mission critical applications environment most of the time we want to see whats happening in Event Logs. In this article we will schedule a task to see the 10 most recent Events log entries in administrator mailbox so that in case of any error or something goes wrong admins can immediately take action to fix the errors.

Steps

We need to create two files and keep them somewhere in your Exchange drives my docs, download or C:\ drive etc where you have full permission to run these file in-case if you have used delegated account for Exchange installation. File names with extension are as below:-

ExchangeServerLast10EventsLog.bat
ExchangeServerLast10EventsLog.PS1

Creating .bat

File Open the ExchangeDatabaseCopyStatus.bat file and paste the following path which can vary to your environment, or as per your Exchange application installation. Most of the people install Exchange Server in default OS drive C:\
 
PowerShell.exe -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\V15\Bin\ExShell.psc1" -Command ". 'C:\Program Files\Update Services\Exchange Bats\Exchange Bats\ExchangeServerLast10EventsLog.PS1'"

You can point to this PowerShell.exe where your Exchange is installed. In this case, it's installed in D:\ so its using that path, the second part of the command is the path of your .PS1 script where you place it.

Creating .PS1 Script


We will open the ExchangeDatabaseCopyStatus.PS1 script in any editor and fill the following information.

$messageParameters = @{
    Subject = "Exchange 2013 Last 10 Event Logs Status Report - $((Get-Date).ToShortDateString())"
    Body = Get-EventLog –LogName Application –Source “MSExchange Common” –EntryType Error –Newest 10 |
         ConvertTo-Html |
         Out-String
    From = "ExchangeLast10Events@mstechguru.ae"
    To = "shakir.hussain@mstechguru.ae"
    SmtpServer = "smtp.mstechguru.ae"
}
Send-MailMessage @messageParameters -BodyAsHtml

In the script you can change Subject value, From Value, To Value and SmtpServer value as per your environment. In From value, we can put any dummy email ID which will later appear in Email from the option. So no need to put any valid email address in From. In To option we have to put some valid email address for Exchange Administrator or the Exchange admins teams who are responsible for Exchange Servers in the organization, so They will receive email notification on daily basis and be well aware of Exchange Server's most recent error Event Logs status in Email.

Scheduling a Task in Exchange


Task scheduling steps can follow from the below link:

Scheduling A Task in Exchange Server

Results in Email


When task will trigger you will receive an email having Exchange most recent 10 Event Logs with status.


Conclusions


This will help Exchange administrators to automate tasks and get results in his/her inbox on daily basis. Admin can also have a history of the Error Events status of Exchange Servers in his/her inbox