I am attaching a command breakpoint for every "Get*" in my powershell session. This command breakpoint involves calling an Action which invokes Write-Host "We are trapped in this code". As you can see below
Eg.
PS /Users/test> Set-PSBreakpoint -Command "Get*" -Action {
>> Write-Host "We are trapped in this code"
>> }
ID Script Line Command Variable Action
-- ------ ---- ------- -------- ------
1 Get* …
PS /Users/test> Get-Runspace
We are trapped in this code
Id Name ComputerName Type State Availability
-- ---- ------------ ---- ----- ------------
1 Runspace1 localhost Local Opened Busy
PS /Users/test>
Now instead of printing
We are trapped in this code
we want to print
We are trapped in this code: Get-Runspace
In this specifically we want to print the command ie. Get-Runspace on which breakpoint was applied. Is there any way to get the hold of the Executing Command within the ScriptBlock.
PS: We have tried $MyInvocation.MyCommand.Name within the script block and various other methods but all of them return null.