joel_wiesmann_automic

:REGISTER_VARIABLE as Powershell Cmdlet (here's the how to...)

Discussion created by joel_wiesmann_automic on Dec 22, 2017

Hi all

REGISTER_VARIABLE is one of the favorite features for many of us. However it only works as part of the process-tab and not if it's written inside of PS1 scripts.

1. Create a INCLUDE (REGISTER#INC) containing the code posted on my gist:
https://gist.github.com/JoelWiesmann/2aa868a35b4b078c9c5b3bcbab4454be

2. Create a Windows JOBS object with Custom Interpreter, :INCLUDE-ing the REGISTER#INC

3. Write your powershell code. Eitherwithin a deployed ps1 or directly in the script tab using the Cmdlet Register-Variable. Example:
Get-ChildItem c:\ | % { $i++; Register-Variable -var "FILE_$i" -value $_.FullName }

4. Execute. Result is attached as screenshot.

The cool thing is, that the Register-Variable Cmdlet can also be included in the developers default environment. The AE-script part won't disturb and everytime the Cmdlet is being called it detects whether it's running in the AE context or not and returns either a verbose message only or executes the Jobmelder.

I'm still doing experiments with it, however I see quiet interesting use-cases where developers use this method to set Escalation / Description information directly in their scripts (i.E. in the header).

Regards & merry x-mas
Joel

Attachments

Outcomes