Skip to content

Register-EngineEvent Powershell.Exiting does not work. #8000

@danielniccoli

Description

@danielniccoli

Steps to reproduce

Register-EngineEvent -SourceIdentifier Powershell.Exiting -Action { Set-Content -Value "Hello there." -Path "$env:TEMP\General Kenobi.txt" }
exit

Instead of exit, the user may also close the Powershell with the x-Button.

Expected behavior

I expect that Powershell executes every command in the -Action parameter before it exits. In this case, I expected that a file General Kenobi.txt would have been written to $env:TEMP.

Actual behavior

Powershell does not execute the action in any case. Not when exiting via exit command and not when exiting by pressing the x-button of the powershell console window.

This not only happens in PS6 but also in PS5.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productWG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions