That is because the code sample you have supplied is using WPF commands (or the command design pattern) and not events, so you need to look up how to handle commanding in Powershell or change the button command into events