Versions Compared

Key

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

...

  • Line 2: The job is executed with a Windows Agent that is assigned by a process class.
  • Line 3-5: Consider to adjust the history_results_directory parameter to point to a valid directory where to store the log files.
  • Line 6: The job is of type "powershell" and will use the Powershell version provided with the server.
  • Line 7: The JobScheduler PowerShell module is imported. The module could be installed with any location in the file system
  • Line 8: The Connect-JS cmdlet is used to authenticate with the JOC Cockpit REST Web Service. The required URL and credentials are specified in a PowerShell profile, see PowerShell CLI 1.2 - Use Cases - Credentials Management
  • Line 910: The target directory specified by the history_results_directory parameter is created should it not exist.
  • Line 13-18: Any previous execution of this job will create a file task.history that stores the latest history entries for which log files have been processed. If such a file exists then the value of the $lastHistory variable is restored and otherwise and an initial query about the last 8 hours of task executions is used to populate the $lastHistory variable.
  • Line 21: The Get-JobSchedulerTaskHistory cmdlet is called 
    • with the parameter -DateFrom  $lastHistory[0].startTime to specify the first most recent history entry to be processed to correspond to the last recently processed history entry.
      • optionally with additional parameters, e.g. to specify the date range for which logs are forwarded  A value -DateFrom (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays(-7).ToUniversalTime() specifies that logs should be forwarded for the last 7 days (from midnight). Keep in mind that dates have to be specified for the UTC time zone. Without this parameter logs will be forwarded for the last day.
      • see the Get-JobSchedulerTaskHistory cmdlet for a full parameter reference.
    • the output of this cmdlet is pipelined to the Tee-Object cmdlet to store new values to the $lastHistory variable and to proceed with the pipeline.
    • the following pipeline step includes to read the task log for each entry reported by the Get-JobSchedulerTaskHistory cmdlet.
    • the next pipeline step includes to select properties from the pipeline that are forwarded to the Set-Content cmdlet that expects the Path and Value parameters. For the Path parameter the output directory and the file name for the log file are specified from the task's start time and job name.
  • Line 24: Finally the values returned by the $lastHistory variable are persistently written to disk for later retrieval.

...

  • Basically the same explanations as for the Windows version of the job apply.
  • Line 7: The PowerShell has to be invoked with pwsh. Consider that any subsequent PowerShell commands are quoted within a string that starts with line 3 and that ends with line 29. 
    • As the string is using a single quote all subsequent PowerShell commands make use of double quotes when required.
    • You could apply a different quoting style, however, quotes have to be consistent.
  • Line 58: As an example a PowerShell profile is invoked that provides the variables for URL and credentials to access the JOC Cockpit REST Web Service. Such profiles can be stored in different locations and can be invoked automatically by pwsh on startup.

...