How to monitor for new evets in eventlog and trigger an action

Arosh Wijepala 161 Reputation points
2022-05-14T14:48:46.827+00:00

I would like to know the logic or the piece of powershell code that can be used to monitor for a service shutdown event and trigger an action. So when the service stopped, event is written to the eventlog. Powershell should detect that and trigger the action. But this service start/stop actions can be several at a given time. So I want to run the powershell script every 5 minutes, detect whether there is a service shutdown event within that time frame and trigger an action. How can I achieve this? Any help would be greatly appreciated.

Thanks.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,128 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,356 Reputation points
    2022-05-23T08:35:57.457+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having query related to Actions while Windows Events occurred.

    Scheduled Tasks should get invoked whenever the event Trigger conditions are met.
    Depending on the Action that is being executed (e.g. Start a program) that may run continually until the process / application is terminated. Event based Triggers should be able to run from startup and before logon.


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments