0
I have a manual routine (involving the Scheduled Task GUI) for creating a scheduled task that triggers on a given set of events from the event log. I would like to automate that process using Powershell (alternatively using some other scripting tool) and I have found a small how-to with some examples, as well as the documentation for New-ScheduledTaskTrigger.
Unfortunately, the docs do not show any view of creating a task for some specific event id. It only lists one specific non-time related trigger - -AtLogOn
.
How would I register such a task? Could for instance Get-Eventlog
be used? New-ScheduledTask mentions "trigger objects", but not how to create them and the docs to Triggers are no longer updated and contains no PowerShell relevant info. The docs for New-ScheduledTaskTrigger
seems like exactly what I want:
The New-ScheduledTaskTrigger cmdlet creates and returns a new scheduled task trigger object.
But as I mentioned above, the docs doesn't mention anything about event ids.
Similar question here https://superuser.com/questions/1481946/how-to-launch-a-bat-file-the-second-internet-disconects-windows-10/1481970#1481970 but with a different event ID.
– spikey_richie – 2019-10-02T08:53:02.897@spikey_richie That's exactly what I don't want :-) As I wrote, I want to do this using Powershell. My current routine involves manually creating the trigger using the gui. The
powershell
tag is also a hint :-) – oligofren – 2019-10-02T08:55:36.997Understood, thanks for updating the question. – spikey_richie – 2019-10-02T08:58:08.610
@spikey_richie Found a solution. It doesn't show how to programmatically build the trigger, but it's a workaround that achieves the same thing. – oligofren – 2019-10-02T09:26:02.550