From 30f98c4cb11d54c8caa73c5923e0031a4c0bb171 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 22 Mar 2024 12:19:05 +0100 Subject: [PATCH] Wait for wmi event using `powershell` --- scripts/Windows/OS/User/Add.ps1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/Windows/OS/User/Add.ps1 b/scripts/Windows/OS/User/Add.ps1 index 34a4b8b1..db271138 100644 --- a/scripts/Windows/OS/User/Add.ps1 +++ b/scripts/Windows/OS/User/Add.ps1 @@ -135,8 +135,13 @@ function Start-EventDrivenTask() { [int]$EventID ); - $identifier = "EventLog$_"; - 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; + powershell -c { + param ( + [int]$EventID + ) + $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 }