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

2024-03-24

例如:

function Foo { 
    [string]$functionName = commandRetrievesFoo
    Write-Host "This function is called $functionName"
}

Output:

PS > Foo
This function is called foo

您可以使用$MyInvocation其中包含有关当前执行内容的一些有用信息。

function foo {
    'This function is called {0}.' -f $MyInvocation.MyCommand
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有办法从函数内检索 PowerShell 函数名称? 的相关文章

随机推荐