Wait for wmi event using powershell

This commit is contained in:
Manuel Thalmann 2024-03-22 12:19:05 +01:00
parent 5f02a650ad
commit 30f98c4cb1

View file

@ -135,8 +135,13 @@ function Start-EventDrivenTask() {
[int]$EventID [int]$EventID
); );
$identifier = "EventLog$_"; powershell -c {
Write-EventLog -LogName Application -Source "Application" -EventId $EventID -Message "This event was created by $env:Username"; param (
Register-WmiEvent -Query "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' AND EventIdentifier=$EventID" -SourceIdentifier "$identifier"; [int]$EventID
Wait-Event -SourceIdentifier $identifier; )
$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";
Wait-Event -SourceIdentifier $identifier;
} -args $EventID
} }