PowerShell based batch processing with the Atria Job Runner

PowerShell based batch processing with the Atria Job Runner

Scheduling PowerShell Jobs

Applies to Atria 15.2 or later

Purpose

PowerShell is a popular and powerful scripting language that is well known by  Microsoft administrators.  
Atria has the ability to schedule PowerShell jobs that can be centrally managed from within Atria.

For more information about the Jobs service, please see this KB - Job Management (Batch Processes)

Deployment

If the extension is available, the "PowerShell" job type will appear in the Job Type drop down menu. If it does not appear like the below, follow these steps.


1. log on to the platform provisioning engine
2. Start an elevated PowerShell session
3. Run the following command
       Import-AtriaExtension -Extension PowerShell

This will enable the extension for use.

Configuration

The configuration is in JSON format and has the following parameters:

filename - the filename of the PowerShell script to execute, the path specified must be accessible from the Primary Provisioning Engine server
variables - this can contain any number of parameters that you'd like to feed into your PowerShell script.  
configValues - use to specify any particular value that is stored in the configuration section of the Atria configuration service.
secretValues - use to specify any particular value that is stored in the secrets section of the Atria configuration service - for example, to extract a connection string
environmentConfigValues and environmentSecretValues extract values that are local to the current environment.  

Example Configuration
      
         {
         "fileName": "c:\\helloworld.ps1",
         "variables": {
                "name": "Tester"
         },
         configValues: ["customerid"],
         secretValues: ["connectionstring_OLM"],
         environmentConfigValues: ["environmentid"],
         environmentSecretValues: ["messaging"]
         }
      
   

Secrets

Secret variables are specified using the variables key, the same as the variables key for the configuration section.  In this case, the values will be encrypted and stored.   Use this feature to store things like API tokens, or usernames and passwords that are needed for this specific job.  Note that once entered, you are unable to view the secrets again and the User Interface will show a blank value for any Secrets.
          {
              "variables": {
                     "apiUser": "xeroapi",         
                     "apiPassword": "#6HUj#j89uYt6%d_o)"                
              },            
          }       

Using Parameters and Secrets 

All variables from the configuration and secrets sections will be injected as variables into your PowerShell script at run time.
e.g.
a variable called "customerid" would create the variable $customerid which can be used in the PowerShell script.
the same applies to any variable that is extracted from the config service or specified in the secrets section for the job.

Writing Log Entries from your Script

The $logger object is provided for you to write log entries back into Atria.
Methods are provided for each of the log levels  AddError, AddWarning, AddInfo, AddDebug and AddVerbose
Each time you log an item, you can provide a unique code and a description.  
Note that The Unique code will be truncated to 20 characters (if longer than 20 characters).

These logger values will be displayed within the output of a Job with the Error code, just like Writing a verbose log or to the host from PowerShell.
Set-Content -Value $Name -Path 'c:\test\name.txt';
Set-Content -Value $Password -Path 'c:\test\password.txt';

$Logger.AddError('MYCODE01', 'This is the user name {0}', $name);
$Logger.AddWarning('MYCODE02', 'This is a warning for user name {0}', $name);
$Logger.AddInfo('MYCODE03', 'This is a info message for user name {0}', $name);
$Logger.AddDebug('MYCODE04', 'This is a debug message for user name {0}', $name);
$Logger.AddVerbose('MYCODE05', 'This is the end of the script');

    • Related Articles

    • Job Management (Batch Processes)

      Applies to Atria 15 and later Introduction Atria Job management is designed to setup, execute and schedule batch processes. The initial implementation uses this feature to execute PSA integration processes (ConnectWise, Kaseya, AutoTask), you can ...
    • Atria Job Runner - Database Maintenance

      Introduction Database Maintenance Jobservice Extension runs a set of scripts to maintain logs, requests, requestlogs and azuresyncjob tables in Atria.   High Level Process Once we run database maintenance Jobservice the process follows the below ...
    • Atria v12.11+ System Requirements

      Overview  The following article provides the prerequisites necessary for the deployment of Atria v12.11+ into your environment.  System Requirements   Environment  Core servers for the platform should be domain joined. Before you can deploy Atria ...
    • Atria Billing Setup User Guide

      Objective This article describes how to configure Atria to utilize the latest billing features. This document outlines the billing setup attributes that should be configured.    Applies to Introduced in Atria version 12.0.0 Billing Setup Overview To ...
    • Integrating ConnectWise with Atria

      Introduction The Atria ConnectWise integration takes billing data from Atria and updates the corresponding service quantities in the ConnectWise company agreement. This document will help you understand how the integration works and what you need to ...