...
Code Block | ||
---|---|---|
| ||
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="/tests/Agent"> <script language="powershell"> echo "job is starting" sleep 10 echo "job is finishing" </script> <monitor name="process_powershell" ordering="0"> <script language="powershell"> <![CDATA[ function spooler_process_before() { $env:files$files = get-childitem * echo $files $spooler_log.info("hallo") return $false$true } ]]> </script> </monitor> <run_time /> </job> |
Example: PowerShell Job with Debug output
The following job shows how to set different ouputs for PowerShell such as:
- Set verbose
Code Block | ||
---|---|---|
| ||
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="Agent01" stop_on_error="no"> <settings > <log_level ><![CDATA[debug1]]></log_level> </settings> <script language="powershell"> <![CDATA[ # Standard PowerShell verbose setting is considered for jobs: $VerbosePreference = "continue" Write-Verbose "job: this is some verbose output" # Standard PowerShell debug setting is ignored for jobs: # $DebugPreference = "continue" # Instead the current log level of the job is applied, e.g. log level "debug1" logs debug messages $DebugPreference = "continue" Write-Debug "job: this is some debug output" Write-Warning "job: this is a warning" # This can be used to throw an error # Write-Error "job: this is an error" # This does not work: Use of Write-Host is not allowed # Write-Host "job: this is some output" ]]> </script> <run_time /> </job> |
...
The integration of the PowerShell CLI into PowerShell jobs is also available. A basic job using the PowerShell CLI might look like this:
Code Block | collapse | true
---|
<job process_class="my_process_class"> <script language="powershell"> <![CDATA[ Import-Module JobScheduler show-status ]]> </script> <run_time /> |
...