Fix non-functioning OneShot script

This commit is contained in:
Manuel Thalmann 2024-08-10 15:13:20 +02:00
parent 270854f435
commit f20523c43b

View file

@ -79,26 +79,30 @@ $null = New-Module {
Set-Stage ([SetupStage]::OneShot);
& $taskSetter $Task;
$job = & {
& {
$identifier = "EventLog$oneShotTrigger";
$log = [System.Diagnostics.EventLog]::new($logName);
$log.EnableRaisingEvents = $true;
$null = Register-ObjectEvent -InputObject $log -EventName EntryWritten -Action {
$entry = $event.SourceEventArgs.Entry;
$entry = $Event.SourceEventArgs.Entry;
$trigger = $Event.MessageData.Trigger;
$identifier = $Event.MessageData.Identifier;
if ($entry.EventID -eq $oneShotTrigger) {
$null = New-Event -SourceIdentifier $identifier;
}
};
if ($entry.EventID -eq $trigger) {
$null = New-Event -SourceIdentifier $identifier;
}
} `
-MessageData @{
Trigger = $oneShotTrigger;
Identifier = $identifier;
};
Start-Job {
Wait-Event -SourceIdentifier $identifier;
Wait-Event -SourceIdentifier $identifier;
};
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "Starting OneShot task ``$(Get-OneShotTask)``";
Remove-Event -EventIdentifier (Wait-Event -SourceIdentifier $identifier).EventIdentifier;
$null = Wait-Event -SourceIdentifier $identifier;
};
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "Starting OneShot task ``$(Get-OneShotTask)``";
$null = Wait-Job $job;
Set-Stage $currentStage;
if (Test-Path $errorPath) {