Last active
April 3, 2020 20:44
-
-
Save deviousasti/03c735687bb076a4f8e214073868958c to your computer and use it in GitHub Desktop.
This task is triggered when a .NET application faults with an exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<Triggers> | |
<EventTrigger> | |
<Enabled>true</Enabled> | |
<Subscription><QueryList><Query Id="0" Path="Application"><Select Path="Application">*[System[Provider[@Name='.NET Runtime'] and EventID=1026]]</Select></Query></QueryList></Subscription> | |
<ValueQueries> | |
<Value name="eventChannel">Event/System/Channel</Value> | |
<Value name="eventRecordID">Event/System/EventRecordID</Value> | |
<Value name="eventSeverity">Event/System/Level</Value> | |
</ValueQueries> | |
</EventTrigger> | |
</Triggers> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<Duration>PT10M</Duration> | |
<WaitTimeout>PT1H</WaitTimeout> | |
<StopOnIdleEnd>true</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit> | |
<Priority>7</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>powershell</Command> | |
<Arguments>D:\Trigger.ps1 -eventRecordID $(eventRecordID) -eventChannel $(eventChannel)</Arguments> | |
<WorkingDirectory>D:\</WorkingDirectory> | |
</Exec> | |
</Actions> | |
</Task> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param($eventRecordID, $eventChannel = "Application") | |
$event = Get-WinEvent -LogName $eventChannel -FilterXPath "<QueryList><Query Id='0' Path='$eventChannel'><Select Path='$eventChannel'>*[System[(EventRecordID=$eventRecordID)]]</Select></Query></QueryList>" | |
$stackTrace = $event.Message | |
if($stackTrace -match "Exception") | |
{ | |
echo "Error Thrown in Application" | |
$stackTrace > trace.txt | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment