Best practices
CmdletBinding
Always add this code snippet at the start, or directly after help section. If the script does not have this parameter PowerShell will not be able to execute the script correctly.
1 2 3 4 5 |
|
EPR will try to start a new PowerShell process for each request it receives with the body from that request as input to stdin.
1 |
|
Avoid using any of the Write-* cmdlets built in to PowerShell (Ex. Write-Verbose, Write-Error, Write-Warning) as they will produce output written back to EPR. Instead, use the Write-CustomLog function in the Easit.ProcessRunner.GlobalFunctions module.
Begin / Process / End
We strongly recommend that you use this structure for the best flow control and error handling.
1 2 3 4 5 6 7 8 |
|
Begin block
To best leverage the built-in function and additional / side loaded modules / scripts we recommend you to add these in the corresponding directory under helpers and add this code snippet.
1 2 3 4 5 6 7 8 9 10 11 |
|
The Set-EPREnvironment function will loop over and load any modules specified as Modules or CustomModules.
In the example above we have saved 3 modules to the modules folder in the helpers folders with the command below.
1 2 3 4 5 |
|
Process block
If you would like to utilize the function Write-CustomLog and globalSettings.json, the following code should be added first in the process block. Please avoid using throw or any other terminating error technique and instead use the return keyword to correctly execute the end block.
1 2 3 4 5 6 7 8 9 10 |
|
To access the exported item from Easit GO we recommend you use the following approach.
1 2 3 4 5 6 7 |
|
You can then access the properties for the item like this.
1 |
|
End block
Use this block for any cleanup, error notification and such.