gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:45:02 25 4
gpt4 key购买 nike

例如:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com