Jobs
Jobs are the history of scripts that have been run.
Last updated
Jobs are the history of scripts that have been run.
Last updated
Copyright 2024 Ironman Software
Jobs are the result of running a script. Jobs are retained based on the script and server level settings.
Jobs can be viewed by clicking the Automation / Jobs page. Click the View button to navigate to the job. Jobs in progress can also been cancelled.
Standard PowerShell streams such as information, host, error, warning and verbose are shown within the output pane.
Storing large amounts of pipeline output can negatively affect performance. You can discard pipeline output by setting the Discard Pipeline setting on scripts.
Pipeline output for jobs is also stored within PowerShell Universal. Any object that is written to the pipeline is stored as CliXml and available for view within the Pipeline Output tab.
You can expand the tree view to see the objects and properties from the pipeline.
Any errors written to the error stream will be available on the Error tab within the job page.
Some jobs will require feedback. Any script that contains a Read-Host
call will wait until there is user interaction with that job. The job will be in a Waiting for Feedback state, and you can respond to that feedback by click the Response to Feedback button on the job page.
You can use Invoke-PSUScript
to invoke jobs from the command line. You will need a valid App Token to do so. Parameters are defined using dynamic parameters on the Invoke-PSUScript
cmdlet.
You can also call UA scripts from UA scripts. When running a job in UA, you don't need to define an app token or the computer name manually. These will be defined for you. You can just call Invoke-PSUScript
within your script to start another script. Both jobs will be shown in the UI. If you want to wait for the script to finish, use Wait-PSUJob
.
You can use the Wait-PSUJob
cmdlet to wait for a job to finish. Pipe the return value of Invoke-PSUScript
to Wait-UAJob
to wait for the job to complete. Wait-PSUJob
will wait indefinitely unless the -Timeout
parameter is specified.
You can use the Get-PSUJobPipelineOutput
cmdlet to return the pipeline output that was produced by a job. This pipeline output will be deserialized objects that were written to the pipeline during the job. You can access this data from where you have access to the PowerShell Universal Management API.
It may be required to return the output from a script's last job run. In order to do this, you will need to use a combination of cmdlets to retrieve the script, the last job's ID and then return the pipeline or host output.
The following example invokes a script, stores the job object in a $job
variable, waits for the job to complete and then returns the pipeline and host output.
If you are using PowerShell Universal 2.4 or later, you can use the -Wait
parameter of Invoke-PSUScript
to achieve this.
The integrated mode allows calling these cmdlets from within PowerShell Universal without an App Token or Computer Name. It uses the internal RPC channel to communicate.
You can set the -Integrated
parameter to switch to integrated mode. This parameter does not work outside of PowerShell Universal.
The following cmdlets support integrated mode.
Get-PSUScript
Invoke-PSUScript
Get-PSUJob
Get-PSUJobOutput
Get-PSUJobPipelineOutput
Get-PSUJobFeedback
Set-PSUJobFeedback
Wait-PSUJob
You can call jobs over REST using the management API for PowerShell Universal. You will need a valid app token to invoke jobs.
To call a script, you call an HTTP POST to the script endpoint with the ID of the script you wish to execute.
You can provide parameters to the job via a query string. Parameters will be provided to your script as strings.
You can set the environment by pass in the environment property to the job context. The property must be the name of an environment defined within your PSU instance.
You can set the run as account by passing in the name of a PSCredential variable to the Credential property.
Variables defined in jobs can be found on the variables page.