Skip to content

Fortified IDDocs

PowershellExecuteToItems

PowershellExecuteToItemValve is a pipeline valve responsible for executing a PowerShell script and converting its output into structured items. It ensures that the execution result is machine-readable and consistent for downstream processing.

A failing script will fail the valve.

Note: Script and arguments does not need to be escaped or surrounded with quotes. Only json-escaping (\ or ") of the configuration is needed.

NameDescriptionDefault valueMandatoryExpanded
executableName and location of the Powershell executable.

C:\Windows\System32\Windows\PowerShell\v1.0\powershell.exe
scriptName of the script to be executedN/A
argumentsA list of arguments to the script.empty list
directoryWorking directory from where the command is executed. Not set means current directory.null
timeoutTimeout for the execution (in seconds)30
execute_initExecutes the script with the parameter "-init" during initialization.false
id_parameterParameter containing the id for the created item(s). Defaults to "tmp_x" where x is the index of the array of json objects."tmp_"
merge_items_parameterMerge the json-object into an existing item based on matching this property.
merge_items_create_newIf a matching item is not found, setting this to true creates a now one. Otherwise discard it.true
  1. Optional Initialization (execute_init)
    • When enabled, the valve performs an initial execution of the configured PowerShell script using the argument init.
Terminal window
powershell.exe -ExecutionPolicy Bypass -File .\script.ps1 -init
  • This step is typically used to prepare the environment, validate dependencies, or pre-load required PowerShell modules.
  • If the initialization fails, the valve aborts execution and returns an error.
  • Default: execute_init = false
  1. Main Execution
    • The valve then executes the PowerShell script with the configured arguments.
    • The output is captured and stored in a temporary state variable before being passed to JsonToItemsValve.
  2. Conversion to Items
    • The JsonToItemsValve converts the script’s JSON output into a list of items usable by subsequent components in the processing pipeline.

Output Format Requirement

The executed PowerShell script must return a valid JSON array ([...]).

Example:

[
{ "id": "001", "status": "OK" },
{ "id": "002", "status": "Failed" }
]

Any other form of output — such as plain text, an empty response, or a JSON object ({...}) — is treated as an error and will cause the valve to fail.

This strict requirement ensures uniform, predictable data handling throughout the system.

Terminal window
param([switch]$init)
function init {
# This is executed during -init
Write-Host 'This is executed during -init'
}
function main {
# This is executed in the pipe (should output a valid json)
Write-Host '[{"User":"[email protected]"},{"User":"[email protected]"}]'
}
if ($init) {
init
return
}
init
main