Fix non-functioning OneShot script
This commit is contained in:
parent
270854f435
commit
f20523c43b
1 changed files with 16 additions and 12 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue