Display the name of the currently executing function

powershell

Solution

The `$MyInvocation` variable contains information about whatever is currently executing:

Function write-FunctionName
{
    write-host ("The name of this function is: {0} " -f $MyInvocation.MyCommand)
}

For more information, see `get-help about_automatic_variables`, or the technet site here.

Problem

How can I retrieve the name of the function that is currently running in powershell? Here is an example of what I want: ``` Function write-FunctionName { write-host "The name of this function is: *SomethingGoesHereButWhat?*" } ``` Then when I execute it, it will display this: ``` >write-FunctionName The name of this function is: write-FunctioName > ``` Can this be done? If so how?

Original source

Related problems