Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Instead of additional job steps or monitors the Add-EventJobSchedulerEvent cmdlet can be used to create events directly within a job:

...

Code Block
languagepowershell
<?xml version="1.0" encoding="ISO-8859-1"?>
<job  order="yes" stop_on_error="no">
    <script  language="powershell">
        <![CDATA[
Import-Module JobScheduler

Add-EventJobSchedulerEvent -EventClass $spooler_task.order().job_chain().name() -EventId "started_$($spooler_job.name())"

echo "job: $($spooler_job.name())"

Add-EventJobSchedulerEvent -EventClass $spooler_task.order().job_chain().name() -EventId "completed_$($spooler_job.name())"
        ]]>
    </script>
    <run_time />
</job>

...

Code Block
languagepowershell
# add an arbitrary event
$event = Add-EventJobSchedulerEvent -EventClass daily_closing -EventId 12345678
 
# wait for the event service to process the request
Start-Sleep -Seconds 3
 
# check the list of events
$events = Get-Event
$events
 
# remove the newly created event
$event | Remove-EventJobSchedulerEvent
 
# think twice before removing all events
Get-EventJobSchedulerEvent | Remove-EventJobSchedulerEvent

Explantions

  • The Add-EventJobSchedulerEvent cmdlet returns an event object that can be used for later pipelining
  • Event processing occurs asynchroneously, therefore newly created events might take some seconds to be available for retrieval..
  • The Get-EventJobSchedulerEvent cmdlet retrieves an array of event objects that are available with JobScheduler.
  • A previously created event object can be pipelined to the Remove-EventJobSchedulerEvent cmdlet.
  • In a more general sense all events as returned from Get-Event can be pipelined to the Remove-Event cmdlet.