Skip to content

Reading inputs in Python, Node.js and PowerShell

Recipes 4.3 to 4.5 each build a useful action in one runtime. This recipe puts the three runtimes side by side and looks at the part people get wrong most often: reading the inputs. What does an Array/string input look like in Python? What happens if an input was left empty? Why does "$inputs.myUrl" print nonsense in PowerShell?

Getting ready

  • Orchestrator 9.x with the Python, Node.js and PowerShell runtimes. On 9.1.1 they’re python:3.14, node:24 and powershell:7.6 (recipe 4.3 shows how to list them).
  • The module com.vcfguide.chapter4, with permission to create actions in it.
  • Nothing else: none of the actions in this recipe needs an environment, a plug-in or a network connection, except the PowerShell module sample in part D.

How to do it

The quickest way to learn how inputs arrive is to ask the runtime. Each of the three actions below takes the same six inputs, writes what it got to the log, and returns, for each input, the type the runtime saw.

  1. In Library > Actions, create the action probeInputsPython in com.vcfguide.chapter4, set the Runtime Environment to Python 3.14, the Return type to Properties, and add these inputs:

    Input Type Run it with
    myUrl string https://vc01.vmw.lab
    myNum number 42
    myFlag boolean ticked
    myList Array/string vc01.vmw.lab, vc02.vmw.lab
    myProps Properties site = lab, owner = vcfguide
    myPassword SecureString any value
  2. Paste this script and save:

com.vcfguide.chapter4/probeInputsPython
SECRET_INPUTS = ["myPassword"]
def handler(context, inputs):
# Log every input without printing secrets.
safe = {}
for key in inputs:
safe[key] = "***" if key in SECRET_INPUTS else inputs[key]
print("Inputs were " + str(safe))
# Read one input that must be there, and one that may be empty.
url = inputs["myUrl"]
num = inputs.get("myNum") or 0
print("myUrl is {0}, myNum is {1}".format(url, num))
# Return the Python type of every input.
types = {}
for key in inputs:
types[key] = type(inputs[key]).__name__
return types
  1. Create probeInputsNode the same way, with Node.js 24 as the runtime and the same six inputs:
com.vcfguide.chapter4/probeInputsNode
var SECRET_INPUTS = ["myPassword"];
exports.handler = function (context, inputs, callback) {
// Log every input without printing secrets.
var safe = {};
Object.keys(inputs).forEach(function (key) {
safe[key] = SECRET_INPUTS.indexOf(key) !== -1 ? "***" : inputs[key];
});
console.log("Inputs were " + JSON.stringify(safe));
// Read one input that must be there, and one that may be empty.
var url = inputs.myUrl;
var num = inputs.myNum || 0;
console.log("myUrl is " + url + ", myNum is " + num);
// Return the JavaScript type of every input.
var types = {};
Object.keys(inputs).forEach(function (key) {
var value = inputs[key];
types[key] = Array.isArray(value) ? "array" : (value === null ? "null" : typeof value);
});
callback(undefined, types);
};
  1. Create probeInputsPowerShell, with PowerShell 7.6 as the runtime and the same six inputs:
com.vcfguide.chapter4/probeInputsPowerShell
$SecretInputs = @("myPassword")
function Handler($context, $inputs) {
# $inputs is a PSCustomObject, not a hashtable: list its fields with PSObject.Properties.
$safe = @{}
foreach ($field in $inputs.PSObject.Properties) {
if ($SecretInputs -contains $field.Name) { $safe[$field.Name] = "***" } else { $safe[$field.Name] = $field.Value }
}
Write-Host "Inputs were $($safe | ConvertTo-Json -Compress)"
# Read one input that must be there, and one that may be empty.
$url = $inputs.myUrl
$num = if ($null -ne $inputs.myNum) { $inputs.myNum } else { 0 }
Write-Host "myUrl is $($url), myNum is $($num)"
# Return the .NET type of every input.
$types = @{}
foreach ($field in $inputs.PSObject.Properties) {
$types[$field.Name] = if ($null -eq $field.Value) { "null" } else { $field.Value.GetType().FullName }
}
return $types
}
  1. Run each action with the values from the table in step 1. Then run each one again with myNum and myList left empty, and compare the logs and results.

  2. Compare what each runtime got. On 9.1.1 the three probes return:

    Input Python Node.js PowerShell
    myUrl (string) str string System.String
    myNum (number) float: 42.0 number: 42 System.Double
    myFlag (boolean) bool boolean System.Boolean
    myList (Array/string) list array System.Object[]
    myProps (Properties) dict object PSCustomObject
    myPassword (SecureString) str, in plain text string, in plain text System.String, in plain text
    any input left empty present, None present, null present, $null
Checked on an embedded Orchestrator 9.1.1, inside VCF Automation, 1 Dec 2026. In PowerShell, $inputs is a PSCustomObject, so $inputs.Keys returns nothing; list the inputs with .PSObject.Properties.
  1. The value your handler returns is turned back into the action’s Return type. The original scripts list the four you’ll use most. Pick one, set the action’s return type to match, and return:

    Return type Python Node.js PowerShell
    boolean True true $true
    string "String Output" "String Output" "String Output"
    number 1234 1234 1234
    Properties or a composite type {"status": "done"} { status: "done" } @{ status = "done" }

    In Node.js, “return” means the second argument of callback, or the value of an async handler (part C). Orchestrator doesn’t check the value against the return type: a Python action with the return type number that returned "not a number" handed the text to its JavaScript caller without an error. Check what you return, or the mistake shows up later, in whatever uses the value.

  1. Node.js is asynchronous: a call such as a DNS lookup or an HTTP request returns at once, and its answer comes later. The original scripts show three ways to write the handler. All three return the string myResult; set the return type to string to try them.

    Synchronous. Nothing to wait for, so the handler returns its value:

handler-sync.js
function someSyncOperation() {
console.log('Sync operation completed');
}
exports.handler = (context, inputs) => {
someSyncOperation();
console.log('Returning result...');
return 'myResult';
}

With the callback. Do the work, then call callback(error, result) once, when it’s finished. This is the form the editor’s sample uses, and the one recipe 4.4 uses:

handler-async-callback.js
function someAsyncOperation() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Async operation completed');
resolve();
}, 50);
});
}
exports.handler = (context, inputs, callback) => {
someAsyncOperation().then(() => {
console.log('Returning result...');
callback(undefined, 'myResult');
}, (err) => callback(err));
}

With async and await. Mark the handler async, await each promise, and return the result. It reads like synchronous code but isn’t: the run finishes when the promise the handler returns settles.

handler-async-await.js
function someAsyncOperation() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Async operation completed');
resolve();
}, 50);
});
}
exports.handler = async (context, inputs) => {
await someAsyncOperation();
console.log('Returning result...');
return 'myResult';
}

These samples use arrow functions, Promise and async, as the originals do. That’s fine in Node.js 24; it would not be in a JavaScript (Rhino) action (recipe 4.1). The second handler adds the (err) => callback(err) branch the original left out, so a rejected promise fails the run instead of leaving it waiting until its timeout.

Checked on an embedded Orchestrator 9.1.1, inside VCF Automation, 1 Dec 2026. All three forms work in Node.js 24. An async handler that throws shows its error only in the run’s log; a JavaScript caller gets IllegalStateException: null.
Section titled “D. PowerShell: a module from the PowerShell Gallery, and PowerCLI”
  1. A third-party module, packed with the action. The original sample uses the Assert module from the PowerShell Gallery to check an input. Save the module next to the script on your workstation, zip both, and import the ZIP as the action’s script:
workstation
mkdir -p vro-powershell-3rdparty/Modules && cd vro-powershell-3rdparty
pwsh -c "Save-Module -Name Assert -Path ./Modules/ -Repository PSGallery"
zip -r --exclude=*.zip -X ../vro-powershell-3rdparty.zip .
vro-powershell-3rdparty/handler.ps1
Import-Module Assert
function Handler($context, $inputs) {
$password = $inputs.password
$password | Assert-NotNull
$password | Assert-Type String
return ""
}

Give the action a password input of type SecureString. Run it once with a value and once without: the second run fails with the assertion’s error, which is the point. A PowerShell environment (recipe 4.5) is the other way to add Assert, and the better one when several actions use it.

Needs a lab check. Not yet tried on 9.1.1: the lab’s tools can’t reach the PowerShell Gallery to download Assert. On a workstation that can, import this ZIP into a PowerShell 7.6 action and check that Import-Module Assert finds the module in ./Modules without changing $env:PSModulePath, and which entry handler value the ZIP needs.
  1. PowerCLI. The original’s vSphere sample connects to vCenter and lists powered-on VMs. Recipe 4.5 builds the same thing with the server, user and password as inputs and enough memory for PowerCLI, and explains when its -InvalidCertificateAction Ignore is acceptable. Use that one.

How it works

One map of inputs. Whatever the runtime, Orchestrator collects the action’s inputs into one map keyed by input name, turns it into JSON, and calls your handler with it as inputs, next to context, which describes the run. The handler’s name and arguments differ only in spelling:

Runtime Handler Read an input
Python def handler(context, inputs) inputs["myUrl"], or inputs.get("myUrl") if it may be missing
Node.js exports.handler = function (context, inputs, callback) inputs.myUrl or inputs["myUrl"]
PowerShell function Handler($context, $inputs) $inputs.myUrl or $inputs["myUrl"]

What each type becomes. Because everything crosses as JSON, an input arrives as the nearest JSON type in your language: text as a string, number as a number, boolean as a boolean, an array as a list, and Properties or a composite type as a dictionary or object. Plug-in objects such as VC:VirtualMachine don’t cross at all (recipe 4.3).

The table in step 6 shows the result on 9.1.1. Two things in it catch people out. A number is always a floating-point number, even when you typed 42: Python prints it as 42.0, so convert with int() before you use it as a count or put it into text. And in PowerShell, $inputs and any Properties input are PSCustomObjects: read a field as $inputs.myUrl, and list them with .PSObject.Properties, not .Keys. A hashtable you return from PowerShell reaches a JavaScript caller as Properties (recipe 4.5).

Strings in PowerShell. In a double-quoted string, PowerShell expands a variable, but not a property of it. "Inputs were $inputs.myUrl" expands $inputs and then prints .myUrl as plain text. Wrap the whole expression in $( ): "Inputs were $($inputs.myUrl)". The original sample has this slip; the probe in step 4 uses $( ) throughout.

Empty inputs. An input left empty reaches your script as None, null or $null; it’s still in inputs, so inputs["myNum"] doesn’t raise a KeyError in Python. Read optional inputs with a default: inputs.get("myNum") or 0 in Python, inputs.myNum || 0 in Node.js (careful: || also swaps a real false, 0 or an empty string for the default), and an explicit $null test in PowerShell.

Secrets. A SecureString input is masked in Orchestrator’s run dialog, but the runtime gets the plain value. The original samples log the whole input map; with a password among the inputs, that writes the password to the run’s log in clear. The probes mask the inputs listed in SECRET_INPUTS before logging.

There's more

Dates. JSON has no date type, so a Date input arrives as text, such as 2026-12-01T09:30:00.000+00:00 on 9.1.1. Parse it on arrival: datetime.fromisoformat() in Python, new Date(inputs.when) in Node.js, [datetime]$inputs.when in PowerShell.

Composite types. A composite type arrives like Properties, with one key per field, and an array of composite types as a list of them. A number field is a float here too: {"name": "disk", "count": 2.0} in Python.

Validate first. Inputs from a form or another workflow can be empty, the wrong type, or text with spaces round it. Check them at the top of the handler and fail with a message that names the input, as recipe 4.8 does for JavaScript. The Assert module in step 8 is one way to do that in PowerShell.

Calling these actions from JavaScript. A JavaScript caller passes inputs as usual: System.getModule("com.vcfguide.chapter4").probeInputsPython(url, 42, true, list, props, password). The inputs go in the order they’re defined on the action.

See also