Question: I'm using a powershell script that also draw a basic interface to simplify some task.
I need to bind a specific click event to a button element, and I'm using this code

```
$button_makeAction.add_Click({
    # my code
})

```

The problem is that, during script execution, I want to bind that button to a different click event. Using the same code it appends another click event and execute both, so I need something like `$button_makeAction.reset_Click` or `$button_makeAction.set_Click` in order to remove the first event code. Is this the correct way?

Answer: 
Register the click-event using `Register-ObjectEvent`. That way, you can find it later and remove it. Example:

```
#Create object and register event
PS C:\> $button = New-Object system.windows.forms.button
$event = Register-ObjectEvent -InputObject $button -EventName Click -Action { Write-Host "TestClick" }

#Action is working
PS C:\> $button.PerformClick()

TestClick

#Removing eventsubscriber
PS C:\> Unregister-Event -SubscriptionId $event.id

#Notice no output on next click
PS C:\> $button.PerformClick()

```
How about adding an IF statement to the event handler and executing code based on a condition?