How to handle close event of PowerShell window if user clicks on Close('X') button

后端 未结 3 768
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 11:25

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:

3条回答
  •  萌比男神i
    2020-12-06 12:19

    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 }
    

提交回复
热议问题