Search notes:

PowerShell cmdLet register-engineEvent

Register an action to be invoked when the PowerShell engine shuts down
$null = register-engineEvent -sourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -action {
  …
}

See also

Powershell command noun: engineEvent

Index