Powershel Forms Change one button's action

Good afternoon,

I’m latelly strugling with my Forms script for a specific action I’d like to do, to help understanding, I’ll show part of codes while explaining.

I have 4 button that each show the exact same thing, we will name them ActionButton

$Data = DL

In that button, another button is Added which we’ll call Buttonexport, uppon clicking on it, it will call a function into a variable and then another function that is a Forms.SaveFileDialog for saving the output of $Data


Issue here is when I click on another of ActionButton, then click on $ButtonExport, here what happens:

1- Script will firstly execute again the first ActionButton clicked on at the begining

2- Then script will execute the newly clicked ActionButton

If I click on a 3rd ActionButton , it will do exactly the 2 step above then will execute the action the 3rd ActionButton .

I tried clearing, closing or removing and adding anew the Buttonexport for every click performed on the ActionButton but it still keep in memory the first called function.


If someone have an idea of how this could be handled, that would very appreciated.


Thank you


You should put your code on GitHub or gist for use to see what you mean. For as you explain it, it’s not clear what use case is.
I’d say record a gif using say, https://www.screentogif.com (or other format) of what you say you are seeing.

If you are reusing variable names, etc., and not clearing them before reuse, even in the same session, code path, then I’d expect it to be populated from a previous run in the same session. Well, based on what you say you are doing.

I think the best way to describe what I’m looking for is how to clear a button’s value, functions, variables… when an action linked to it is done
I tried $From.Controls.clear($Button) but it doesn’t work

From what I found, most people reset the complete form, but I’m looking for a way to avoid that