Versions Compared

Key

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

...

The following job explains how to use different output channels for PowerShell such as:

 

Code Block
linenumberstrue
<?xml version="1.0" encoding="ISO-8859-1"?>
<job  process_class="my_Agent" stop_on_error="no">
    <settings >
        <log_level ><![CDATA[debug1]]></log_level>
    </settings>

    <script  language="powershell">
        <![CDATA[
# Use Write-Output or Echo cmdlets to write to the JobScheduler log
Write-Output "job: this is some output"
echo "job: this is some output"

# This does not work: Use of Write-Host cmdlet is not applicable
# Write-Host "job: this is some output"


# Standard PowerShell verbose setting is considered for log output:
$VerbosePreference = "continueContinue"
Write-Verbose "job: this is some verbose output"

# Standard PowerShell debug setting is considered for log output:
$DebugPreference = "continue"
# In addition the current log level of the job has to be set, e.g. log level "debug1" logs debug messages
Write-Debug "job: this is some debug output"

# creates a warning for the job
Write-Warning "job: this is a warning"

# can be used to throw an error
# Write-Error "job: this is an error"
        ]]>

    </script>

    <run_time />
</job>

Explanations

  1. Using PowerShell standard output
    • Use of the Write-Output and Echo cmdlets is applicable.
    • Use of the Write-Host cmdlet is not applicable for PowerShell jobs as the cmdlet requires a PowerShell host console to be available (powershell.exe), whereas JobScheduler runs PowerShell in a process without interaction.
  2. Using PowerShell verbose output
    • The standard PowerShell verbosity setting is considered for log output
    • Use $VerbosePreference = "Continue" 
    • Subsequently use the Write-Verbose cmdlet.
  3. Using PowerShell debug messages
    • The PowerShell debug setting is considered for log output in jobs by use of $DebugPreference = "Continue"
    • In addition, the current log level of the job has to be set, e.g. log level debug1 will log debug messages.
      • With the JobScheduler log level being switched to info no debug output is written to the log file.
      • With the JobScheduler log level being switched to debug1debug2, ..., debug9 then debug output is added to the log.
  4. Using PowerShell Warnings
    • Warnings are created by use of the Write-Warning cmdlet. Such warnings create corresponding warnings in the JobScheduler Master that are visible from the log and that might trigger a notification by mail.
  5. Using PowerShell Error Messages
    • Use of the Write-Error cmdlet will create a job error that is visible from the log and that triggers subsequent actions as e.g. notification by mail, stopping the job, suspending an order etc. 

...

JobScheduler PowerShell CLI for

...

Jobs

...

Info
  • The feature is only available in case your Agent is running on a machine with PowerShell available
  • For more information about how to install and to use the PowerShell CLI module for an Agent see PowerShell Command Line Interface - Introduction

 

The JobScheduler PowerShell CLI is available for PowerShell jobsThe integration of the PowerShell CLI into PowerShell jobs is available as well. A basic job using the PowerShell CLI might look like this:

info
Code Block
 <job<?xml version="1.0" encoding="ISO-8859-1"?>
<job process_class="my_Agent">
 	<script language="powershell">
 		<![CDATA[

Import-Module JobScheduler
show-status

 

 
# display summary information
Show-Status
 
# retrieve the number of available job chains
( Get-JobChain ).count
		]]>
 	</script>
	<run_time />
</job>

Explanations

  • The

...

  • PowerShell CLI is activated by the Import-Module JobScheduler command.
  • For a complete list of cmdlets available from the PowerShell CLI see PowerShell CLI - Cmdlets

...

Anchor
powershell-as-a-shell
powershell-as-a-shell
Compatibility between PowerShell and Shell

As mentioned before, PowerShell Jobs should be seen PowerShell jobs can be considered as a migration path for shell jobs. That means, This suggests that every shell job should can possibly be converted (with a few changes) to a PowerShell job. 

...

Returning a parameter and its value to an Order

Setting a parameter in for an order (for instance parameter name1 with the initial value value1) and modifying the value to value2 and returning the parameter to the order so that the next job chain node uses the new value. For PowerShell this works using the API methods for method available from $spooler_task.order():

Code Block
# Example Shell: 
echo name1 = value2 >> %SCHEDULER_RETURN_VALUES%

# Example PowerShell: 
$spooler_task.order().params().set_value( "name1", "value2" )

...

References

Reference Documentation

...