typera5
typera53d ago

PowerShell in Windmill: Data Passing Through For Loops

Looking for guidance on using PowerShell scripts in Windmill flows, particularly when passing data between scripts separated by for loops. Could anyone please share examples of how to effectively structure this flow and manage data transfer between the PowerShell scripts?| I am returning data as JSON or objects from scripts, but I can't figure out how to use it in the subsequent steps.
15 Replies
rubenf
rubenf3d ago
You want to pass the data from one iteration of a forloop to another ?
typera5
typera53d ago
yep
rubenf
rubenf3d ago
Right now you'd have to use custom flow user state but the sdk for powershell doesn't have it so you will have to use a typescript/python script after your powershell script to set and before to get it which is a lot of boilerplate
rubenf
rubenf3d ago
GitHub
windmill/typescript-client/client.ts at main · windmill-labs/windmill
Open-source developer platform to power your entire infra and turn scripts into webhooks, workflows and UIs. Fastest workflow engine (13x vs Airflow). Open-source alternative to Retool and Temporal...
rubenf
rubenf3d ago
It would likely not be incredibly hard to add it to https://github.com/windmill-labs/windmill/blob/main/powershell-client/WindmillClient/WindmillClient.psm1 but I'm not super qualified in Powershell
GitHub
windmill/powershell-client/WindmillClient/WindmillClient.psm1 at ma...
Open-source developer platform to power your entire infra and turn scripts into webhooks, workflows and UIs. Fastest workflow engine (13x vs Airflow). Open-source alternative to Retool and Temporal...
typera5
typera53d ago
So need to wrap powershell scripts wtih ts/python scripts to convert them and pass them down?
typera5
typera53d ago
is that to get the data out from the earlier flow step (powershell script) to thesubsequent steps?
rubenf
rubenf3d ago
normally you do not need to do this, you can just refer to the output of an id but within a forloop that's not possible given that the same id refer to a previous iteration so you have to use flow user state (or at least waiting for us to have special expressions to refer to previous iteration)
typera5
typera53d ago
Thank you Ruben. A larger issue that it seems I am having is passing data between powershell scripts as part of a flow. I tried it as an object and json string and nothing works. However passing object data in Typescript works as expected. Could it be that there's no support to handling objects with powershell scripts?
rubenf
rubenf3d ago
it's because powershell doesn't support objects, just strings similar to bash, it's a limitation of the language
typera5
typera53d ago
i tried working with json as a string and similar thing, output works, input fails to be received
rubenf
rubenf3d ago
If you can send us a minimal reproduction we can take a look but it works that's for sure
typera5
typera53d ago
thank you, will do. I found my issue, when passing object data between powershell scripts, the output not only needs to be a string with json but the json needs to be compressed (escaped and without line breaks) otherwise it cant be used in the input for the next script. Thank you for your quick reply by the way, it helped greatly!
rubenf
rubenf3d ago
That does sound like a bug, we will take a look