How would I run a powershell script that would run on either, the exit
command, or the shell closing. I would want this script to run on every shell close not just for one shell.
Script
Using Register-EngineEvent you can do this:
Register-EngineEvent PowerShell.Exiting –Action { 'Type your Code' }
# Alternatively with hiding the event:
Register-EngineEvent PowerShell.Exiting -SupportEvent –Action { yourExitFunction; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With