I want to run some code before PowerShell 2.0 window is closed. For this I tried:
PS > register-engineevent PowerShell.Exiting -action {get-process | out-file c:
Unfortunately, you can't do this. The only time an exiting event will get called is if you type "exit" at the PowerShell prompt.
This is how I hook up my exiting event:
$null = Register-EngineEvent -SourceIdentifier `
([System.Management.Automation.PsEngineEvent]::Exiting) -Action { # Put code to run here }