function - 有没有办法从函数内检索 PowerShell 函数名称?

标签 function reflection powershell

例如:

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/

相关文章:

java:切换和反射哪个效率更高?

java - 使用其值获取接口(interface)常量名称

c# - 不同 MVC 版本的不同 NuGet Web.Config.Transforms

javascript - 从 PowerShell 脚本运行 javascript 文档

powershell - 如何在 PowerShell 中将日期范围拆分为每月的子范围?

Perl 作用域函数奇怪吗?

c++ - 如何从方法返回动态指针数组

java - 访问类属性我的名字

r - 在不附加包的情况下评估包环境中的功能

c++ - 在for循环C++中调用Void函数