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
You want to pass the data from one iteration of a forloop to another ?
yep
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
you're missing this: https://github.com/windmill-labs/windmill/blob/main/typescript-client/client.ts#L472
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...
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...
So need to wrap powershell scripts wtih ts/python scripts to convert them and pass them down?
just to use the getFlowUserState and setFlowUserState
it's just an api call to windmill
it's those: https://app.windmill.dev/openapi.html#tag/job/POST/w/{workspace}/jobs/flow/resume/{id}
wrong api: https://app.windmill.dev/openapi.html#tag/job/GET/w/{workspace}/jobs/flow/user_states/{id}/{key}
is that to get the data out from the earlier flow step (powershell script) to thesubsequent steps?
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)
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?
it's because powershell doesn't support objects, just strings
similar to bash, it's a limitation of the language
i tried working with json as a string and similar thing, output works, input fails to be received
If you can send us a minimal reproduction we can take a look
but it works that's for sure
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!
That does sound like a bug, we will take a look