Fix non-functioning events

This commit is contained in:
Manuel Thalmann 2024-03-22 14:51:17 +01:00
parent 30f98c4cb1
commit 5e6eebf8ad

View file

@ -141,7 +141,17 @@ function Start-EventDrivenTask() {
)
$identifier = "EventLog$EventID";
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username";
Register-WmiEvent -Query "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' AND EventIdentifier=$EventID" -SourceIdentifier "$identifier";
$applicationLog = Get-EventLog -List | Where-Object { $_.Log -eq "Application" };
Register-ObjectEvent -InputObject $applicationLog -EventName EntryWritten -Action {
$entry = $event.SourceEventArgs.Entry;
if ($entry.EventID -eq $EventID) {
New-Event -SourceIdentifier $identifier;
}
};
Wait-Event -SourceIdentifier $identifier;
} -args $EventID
}