How to create a TaskSchedule based on an Event Viewer event and import it using Powershell?

How to create a TaskSchedule based on an EventViewer event and import it using Powershell?

This is useful when triggering a distinct set of instructions is needed or execute something specific based on an Event registered in EventViewer.

For example, as a workaround, the service can be restarted when a known error is noticed.

Create the Task:
  1. Open the EventViewer
  2. Select the Event
  3. Right Click it and select "Attach task to this Event..."
  1. Name the task
  1. Press Next
  2. Press Next
1.png
  1. Select "Start a program" in the Action page
  1. Press Next
  2. Select the Program and its arguments
  3. For example run a powershell script called alerts.ps1
  • Program\Script: powershell
​​​​​​ Add arguments (optional): -File "C:\Users\your_username\Desktop\alert.ps1"
  1. Press Next
  2. Select "Open the Properties dialog for this task when i click Finish" to tweak the configuration further
  1. Press Finish
  2. Select the User and privileges where the task should run and Configure for the OS version



  1. Press OK

Exporting the Task:

  1. Open TaskScheduler
  2. Go to Event Viewer Tasks under the Library

  1. Select your newly created task
  2. Click Export

  1. Chose a destination and Filename

  1. Press Save.

Creating it on Another machine using Powershell
  1. Open Powershell
  2. Run the Command
PS C:\> Register-ScheduledTask -Xml (get-content 'XMLFILEPATH' | out-string) -TaskName "Weekly System Info Report"