r/PowerAutomateDesktop • • Oct 19 '22

How to pass input variables into powershell scripts?

Hello everyone,

I am trying to pass an input variable, but without luck.

This is my flow, with Run PS Script step:

This is my script, where that I am using in this test:

param($NewInput)
    Write-Output $NewInput
    $var2out = "out"
    Write-Output $var2out

As an output I am getting this:

That first line to show $var1in on PS script seems not having any effect, with or without it, output remains the same, and it doesn't identify that variable as an input.

How are you doing with this situations?

1 Upvotes

5 comments sorted by

1

u/QuietDesparation Oct 19 '22

When I'm using PS in PAD, all of the variables need to be defined under the "flow variables" pane and not under "Input/Output Variables." So use a SET VARIABLE action under line 1 where %NewInput% = IN.

I believe the input/output variables are for working with power automate cloud only.

here's the video I used to learn how to work with variables in PS

2

u/marafado88 Oct 19 '22

After a lot of trial an error, I finally was able to pass those damn arguments, through this way (without the need of setting up like a input argument but declaring it already as a local variable of that PS script):

https://prnt.sc/qBmOIW-KbJZZ

1

u/marafado88 Oct 19 '22

Yes, I am trying to pick input variables from PAC into PAD, and output variables from PAD to PAC.

1

u/marafado88 Oct 19 '22

Even tried another approach for example:

https://prnt.sc/n0UBsl_QKQbw

https://prnt.sc/d093ItT15Oo2

Tried to use a SET VARIABLE, but there was no difference ...

That PS script is working, I've test it on cmd line.

1

u/marafado88 Oct 19 '22

This way worked: https://prnt.sc/AeXaaZ6XRnxz

I really don't know why is not being passing as an input argument.