例如:
function Foo {
[string]$functionName = commandRetrievesFoo
Write-Host "This function is called $functionName"
}
输出:
PS > Foo
This function is called foo
最佳答案
您可以使用$MyInitation
,其中包含有关当前执行内容的一些有用信息。
function foo {
'This function is called {0}.' -f $MyInvocation.MyCommand
}
关于function - 有没有办法从函数内检索 PowerShell 函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3689543/