Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell profile "on exit" event?

Tags:

powershell

I'm looking for a way to automatically do some clean up tasks when the PowerShell session quits. So for example in my profile file I start a process which needs to run in the background for quite a lot of tasks and I would like to automatically close that process when I close the console.

Is there some function the PowerShell automatically calls when closing the session as it does with prompt when displaying the prompt?

like image 649
poke Avatar asked Mar 12 '10 23:03

poke


1 Answers

There is the Register-EngineEvent cmdlet which you can use to attach an event handler to the Exiting event:

Register-EngineEvent PowerShell.Exiting -Action { ... }

Note however, that this event will not be fired if you close the console window.

like image 187
Joey Avatar answered Oct 27 '22 22:10

Joey