Universal Automation is a platform for executing and scheduling PowerShell scripts. In this post, we will look at how to set up two different types of schedules and view the output from executed jobs.

Creating a New Script

In Universal Automation, scripts can be added to the system either through the PowerShell cmdlets, REST API or via git integration. In this post, we will use the PowerShell cmdlets to manage the Universal Automation platform. The cmdlets use the UA REST API. Changes that are made through the REST API are synchronized with an internal git repository.

To create a simple script, use the New-UAScript cmdlet. You can specify any PowerShell script you’d like in the ScriptBlock parameter. In this example, we’re creating a script to check the status of the IronmanSoftware.com website, how large the response was and how long it look to return the request.

Scheduling a Script

Once your script has been created you can schedule it. The first type of schedule we will use is a CRON based schedule. CRON expressions allow for fine-grained control of how your script runs. You can use a website, like crontab guru, to generate expressions that meet your needs. There are also some basic schedules built into the Universal Automation dashboard.

After generating the schedule, you can now use it with the New-UASchedule cmdlet. You’ll need an instance of the Script object which you can get from either New-UAScript or Get-UAScript. This example CRON expression runs every 2 minutes.

Another method of scheduling is to run a continuous schedule. Continuous schedules will run as soon as the previous run has finished. You can also configure a delay between each run. This may be handy for scripts that may take a variable amount of time to run but you want them to run as frequently as possible. In this example, we are running our script continuously with a 2-minute delay between each run.

Viewing Script Output

Now that a schedule has been defined, you’ll be able to see the output of each job run in the Universal Automation Dashboard.

To view a job’s output, you can click the job ID from within the Past Jobs grid.

The output tab will show the text output from the different PowerShell streams. You’ll be able to see Errors, Warnings, Debug, Verbose and Informational output here.

In addition to viewing the text output for a job, you also view the pipeline output. In our example script, we are returning a hashtable to the pipeline with information about the web request that we performed. If you click the pipeline output tab, you’ll see that you can get information about each object returned to the pipeline.

You can also retrieve this information via PowerShell. The pipeline output is stored within the UA database as CliXml. The CliXml can be retrieved with the Get-UAJobPipelineOutput (or the Receive-UAJob alias). You’ll see that the output is persisted as a hashtable.

Conclusion

In this post, we looked at how to schedule PowerShell scripts in Universal Automation and view the output in the UA dashboard and on the command line. Look out for more posts covering various topics in UA.