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.
   
   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.
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');