显示当前正在执行的功能的名称

Win*_*red 19 powershell

如何检索当前在PowerShell中运行的函数的名称?这是我想要的一个例子:

Function write-FunctionName
{
write-host "The name of this function is: *SomethingGoesHereButWhat?*"
}
Run Code Online (Sandbox Code Playgroud)

然后,当我执行它时,它将显示:

>write-FunctionName

The name of this function is: write-FunctioName

>
Run Code Online (Sandbox Code Playgroud)

可以这样做吗?如果是这样的话?

gor*_*ric 22

$MyInvocation变量包含有关当前正在执行的任何信息:

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

有关更多信息,请参阅此处get-help about_automatic_variables的technet网站.