How to pass variables between tasks in runbooks using PowerShell? | Nutanix Community
Skip to main content

Hi all.

I’ve been searching all over the Internet, and the Nutanix documentation, to figure out how to pass variables from one task in a runbook to the next. I know that I need to print it to the console in the format “statusMessage = ‘This is the status message’” but so far I’ve tried with Write-Host, Write-Output, and Write without any luck.

I’ve also tried using both @@{statusMessage}@@ and @@{Task1.statusMessage}@@ in the next step without any difference.

How am I supposed to do this, and why isn’t it properly documented?

Thanks.

I believe you can set the task ‘Type’ to ‘Set Variables’ and then ‘Script Type’ to ‘Powershell’.

Defined what variable you want to pass along in the Powershell:

Write-host "pass_var=VALUE"

Then at the output section below, put in pass_var.

Also, create a variable ‘pass_var’ in the runbook under the ‘Configuration’ tab to hold this value.

 

Give it a try and good luck.

-Joe

 


Hi Martin,

Sorry to hear you couldn’t find what you are looking for. Please follow the steps Joe suggested, you can also have a look to our documentation: Creating a Set Variable Task

If you are still facing any issue, please don’t hesitate to leave a message.

Regards,

Jose


Hi Joe!

I now realize that I forgot to add the variable to the configuration. /facepalm

Thanks for the quick reply, I’ll give it a try. 


Hi Jose.

Thanks for the quick reply and the link to the documentation.

Do I really have to select the task type as Set Variable though? I can’t remember having to do that previously. Using a task of type Execute, writing the variable to the console, and including it in the configuration as Joe pointed out, would be enough IIRC.


Martin,

You have to use set variable always when you are creating custom variables. It’s the only way where you get an Output textbox. There you write the Calm variable that will get the value that you are printing out in your script.

Built-in macros that start with calm_, or name, address…, they don’t need to be set because they are part of the system. 


Thanks Jose for the clarification.

I am obviously misremembering the POC we did last year. :)