Powershell script task
A powershell script task will inject and execute the same powershell script on several windows nodes concurrently.
This kind of task allows you to maintain the scripts of all your servers through a single interface.
This only works with Windows nodes.
Here is an example:
Write-Host 'Hello!'
Using project constants
Project constants can be used in the script content as environment variables prefixed with CPC_ (for CTFreak Project Constant).
Here’s an example using a project constant named NUMBER_OF_RETENTION_DAYS:
Write-Host "Delete backup files older than $env:CPC_NUMBER_OF_RETENTION_DAYS days"
…
If you later decide to increase the retention period of your backups, you’ll only need to modify the constant value to affect all cleanup scripts referring to it.
Using task parameters
Like project constants, task parameters can be used in the script content as environment variables prefixed with CTP_ (for CTFreak Task Parameter).
Here’s an example using a text task parameter named FIRST_NAME:
Write-Host "Hello $env:CTP_FIRST_NAME !"
Task parameters values are converted to text format when assigned to an environment variable.
The following conversion rules are applied according to parameter type:
- Checkbox → Checked:
true, Unchecked:false - Date → Formatting with the
YYYY-MM-DDpattern - Selector, Integer and Text → No specific formatting
Task characteristics
In addition to the common task characteristics, here are those specific to powershell script tasks.
Node Set filter
Filter (by names and tags) the nodes on which the script will be executed.
NB: This filter is combined with the filter applied at the project level.
Max. number of concurrent node executions
When a script is executed on several nodes, you can specify the maximum number of nodes to be processed concurrently.
Max. number of script execution retries
Maximum number of retry attempts if the script execution fails on a node. Defaults to 0 (no retry).
Delay between retries
Delay in seconds between retry attempts. Defaults to 0 (immediate retry).
Log output
Controls when node execution logs are retained:
- Always – logs are kept for every execution
- On failure or abort – logs are kept only when the execution fails or is aborted
- Never – logs are discarded