I work on a PowerShell debugger implemented as a script, Add-Debugger.ps1. It looks peculiar perhaps but there are use cases for it.
All works well except when the debugger stops at a breakpoint in a script module. One of the debugger functions is to execute interactively typed user commands and show results. The problem is that these commands are not invoked in the current script module scope but "somewhere else".
The problem may be worked around if the current module is known, say $module.
Then commands invoked as $module.Invoke() would work in the module scope.
But how to find/get this $module? That is the question.
NB $ExecutionContext.SessionState.Module does not seem to help, even if I get it using Get-Variable -Scope 1.
Because $ExecutionContext is for the DebuggerStop handler, not its parent in the module.
And Get-Variable is invoked "somewhere else" and does not get variables from the module.