Fix non-functioning OneShot script
This commit is contained in:
parent
270854f435
commit
f20523c43b
|
@ -79,26 +79,30 @@ $null = New-Module {
|
||||||
Set-Stage ([SetupStage]::OneShot);
|
Set-Stage ([SetupStage]::OneShot);
|
||||||
& $taskSetter $Task;
|
& $taskSetter $Task;
|
||||||
|
|
||||||
$job = & {
|
& {
|
||||||
$identifier = "EventLog$oneShotTrigger";
|
$identifier = "EventLog$oneShotTrigger";
|
||||||
$log = [System.Diagnostics.EventLog]::new($logName);
|
$log = [System.Diagnostics.EventLog]::new($logName);
|
||||||
|
$log.EnableRaisingEvents = $true;
|
||||||
|
|
||||||
$null = Register-ObjectEvent -InputObject $log -EventName EntryWritten -Action {
|
$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) {
|
if ($entry.EventID -eq $trigger) {
|
||||||
$null = New-Event -SourceIdentifier $identifier;
|
$null = New-Event -SourceIdentifier $identifier;
|
||||||
}
|
}
|
||||||
};
|
} `
|
||||||
|
-MessageData @{
|
||||||
Start-Job {
|
Trigger = $oneShotTrigger;
|
||||||
Wait-Event -SourceIdentifier $identifier;
|
Identifier = $identifier;
|
||||||
Wait-Event -SourceIdentifier $identifier;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "Starting OneShot task ``$(Get-OneShotTask)``…";
|
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "Starting OneShot task ``$(Get-OneShotTask)``…";
|
||||||
$null = Wait-Job $job;
|
Remove-Event -EventIdentifier (Wait-Event -SourceIdentifier $identifier).EventIdentifier;
|
||||||
|
$null = Wait-Event -SourceIdentifier $identifier;
|
||||||
|
};
|
||||||
|
|
||||||
Set-Stage $currentStage;
|
Set-Stage $currentStage;
|
||||||
|
|
||||||
if (Test-Path $errorPath) {
|
if (Test-Path $errorPath) {
|
||||||
|
|
Loading…
Reference in a new issue