【问题标题】:How to get powershell function source with full header如何获取带有完整标头的powershell函数源
【发布时间】:2022-08-13 21:37:20
【问题描述】:

如此处所见https://superuser.com/questions/414036/get-definition-of-function-and-echo-the-code 这将获得测试功能的主体

${function:test-function}

但不是带有参数的测试函数的标题

  • 你能举个例子说明你在追求什么吗?

标签: powershell


【解决方案1】:

您必须自己添加缺少的部分才能形成完整的函数定义:

$funcDef = "function test-function { ${function:test-function} }"

如果您在变量中给出了函数名称,或者您希望避免重复函数名称:

$funcName = 'test-function'

$funcDef = "function $funcName {{ {0} }}" -f (Get-Item function:$funcName).Definition

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-09
    • 2011-04-08
    • 2018-08-08
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    相关资源
    最近更新 更多