Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run script on powershell exit

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

like image 597
XAMPPRocky Avatar asked Jan 08 '23 01:01

XAMPPRocky


1 Answers

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; }
like image 81
Avshalom Avatar answered Jan 14 '23 17:01

Avshalom