Versions Compared

Key

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

...

Code Block
languagepowershell
linenumberstrue
Import-Module JobScheduler
Use-JobSchedulerMaster http://localhost:4444

echo "begin of test script"

$order = Add-JobSchedulerOrder -JobChain /some_path/some_job_chain
While ( ( $order | Get-JobSchedulerOrder -NoCache ).StartTime )
{
	Start-Sleep -Seconds 10
}

$orderHistory = $order | Get-JobSchedulerOrderHistory
echo "order completed with state '$($orderHistory.State)' at '$($orderHistory.EndTime)'"


echo "end of test script"

Explanations

  • Line 1: The Import-Module statement is used if the JobScheduler CLI module is not loaded from a profile
  • Line 2: The Use-JobSchedulerMaster cmdlet is used for standalone scripts only. This is not reqired for use with It should not be used with PowerShell Jobs.
  • Line 6: Adds a temporary ad hoc orders order to the specified job chain, see Add-JobSchedulerOrder.
    • The order identification is not specified but is generated by the JobScheduler Master.
    • The resulting $order object contains the order identification.
  • Line 7: Repeated checks are executed in a loop repeatedly checks to verify if the order is completed.
    • The newly added order is piped to the Get-JobSchedulerOrder cmdlet that returns and an object with a StartTime property should the order still be running.
    • A sleep interval reduces the frequency of checks for completion of the current order.
  • Line 12: Permanent orders are permanently available from the JobScheduler memory. Temporary ad hoc orders are removed from the JobScheduler memory after completion. Therefore the temporary ad hoc orders order is retrieved from the order history instead of the JobScheduler memory.
  • Line 13: The order history provides information about the order's end time and end state that can be used to identify successful or failed execution.

...