Is there a way to retrieve a PowerShell function name from within a function?
function, powershell, reflection
Solution
You can use `$MyInvocation` which contains some useful information about what is currently executed.
function foo {
'This function is called {0}.' -f $MyInvocation.MyCommand
}
Problem
For example: ``` function Foo { [string]$functionName = commandRetrievesFoo Write-Host "This function is called $functionName" } ``` Output: ``` PS > Foo This function is called foo ```