Friday, June 5, 2015

Powershell monitor event log and in case of specific error restart the related service

Hi,
I had to monitor some service on some specific servers. In particular when a specific event appears on the event log I had to restart a service. Obviously before deciding how many events to analyze before undertake any action you have to check your event viewer and know  how frequently it changes.







Improvable ? For sure yes....like everything in this life.
Instead of remit the execution of the script to your "statistical view" you can write some events in the event log to be sure that the script will analyze and find the right section of the event list avoiding that it could consider an event already triggered.
ATTENTION : PLEASE ADD THE $DATE VARIABLE IN THE FORMAT THAT YOU PREFER.




Obviously first of all you have to register the new event log source (only one time per server) or you can include a check that verify whether the source exists.
Anyway to register a new source the code is :



ATTENTION : PLEASE ADD THE $DATE VARIABLE IN THE FORMAT THAT YOU PREFER.

No complications, no tricks, only the essential.
Hope this helps.
See you soon.

No comments:

Post a Comment