AE - Embedded AE scripting in PowerShell is always executed

Document ID : KB000103495
Last Modified Date : 05/07/2018
Show Technical Document Details
We want to use Automic script functions inside a PowerShell script.
However, it does not work as expected.
The Automic function is inside a PowerShell function so, it should only be executed if the PowerShell function is called.
This is not the case, the Automic function is always executed. Do you know if we can prevent this behavior?
  • An example script
:BEGIN_EXT_INT powershell

:SET &errorOccured# = "False"
write-host errorOccured value: &errorOccured#

! Function to stop script and write result to variable if an error occured
Function errorHandling ($str) {
  write-host ($str)
  write-host "ERROR occured: errorOccured variable set to True.`r`n"
: SET &errorOccured# = "True"

write-host errorOccured value: &errorOccured#

: END_EXT_INT powershell
  • The job report will look something like this
c:\>powershell -ExecutionPolicy Unrestricted -File C:\Users\ntd\Downloads\windowsagent\Resources\0001\0001041139\0001041139_0001.ps1 
errorOccured value: False
errorOccured value: True
I believe that the way you mix Automic script function with PS is not how it work.
You better change your PS function and somehow save it to a PS variable.
Then you can use our :REGISTER_VARIABLE to store the PS value to Automic variable.
Additional Information: