I have created a PowerShell script containing the FileSystemWatcher which creates several file change events. It works perfectly fine when running it within PowerShell ISE, but my end goal is to be able to run this as a background task that's not in PowerShell ISE.
I then started to look into wrapping the code within a GUI which I have done and it kind of works. When I run the code it creates a form containing 2 buttons, when you click button1 I want this to start the code and pressing button2 stops the code or have a handler so when I press a certain key the code stops.
What I'm seeing is when I press button1 the script starts and runs, but I cant cancel it without closing the console window that's behind. Also what I'm noticing, when running through PowerShell ISE I get an email notification of the event that has occurred, when this is running through the GUI I have created, it notices the files changing but I don't get an email notification.
Could anyone assist please?