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.
Creating the Task
- Open the EventViewer
- Select the Event
- Right Click it and select "Attach task to this Event..."
9. Select the Program and its argumentsFor example we are running a powershell script called alerts.ps1
Add arguments (optional): -File "C:\Users\your_username\Desktop\alert.ps1"
10. Press Next
11. Select "Open the Properties dialog for this task when i click Finish" to tweak the configuration further
12. Press Finish
13. Select the User and privileges where the task should run and Configure for your OS version
14. Press OK
Exporting the task
- Open TaskScheduler
- Go to Event Viewer Tasks under the Library
- Select your newly created task
- Click Export
- Chose a destination and Filename
- Press Save
Creating it on another machine using Powershell
- Open Powershell
- Run the Command
PS C:\> Register-ScheduledTask -Xml (get-content 'XMLFILEPATH' | out-string) -TaskName "Weekly System Info Report"