gpt4 book ai didi

powershell - 有没有办法让 Powershell 5 的 Get-Help 解析当前脚本?

转载 作者:行者123 更新时间:2023-12-03 16:24:37 24 4
gpt4 key购买 nike

我有一个非常简单的脚本:

function a-func {

}

<#
.Synopsis
Testing Get-Help
#>
function another-func {

}

Get-Help another-func

我没有装有 Powershell 3 或 4 的机器来仔细检查,但我似乎记得这在 PS 5 之前有效。在 Powershell 5.0 控制台中,这是输出:

C:\Users\Administrator\Documents\WindowsPowerShell> .\testhelp.ps1 Get-Help : Get-Help could not find another-func in a help file in this session. To download updated help topics type: "Update-Help". To get help online, search for the help topic in the TechNet library at http://go.microsoft.com/fwlink/?LinkID=107116. At C:\Users\Administrator\Documents\WindowsPowerShell\testhelp.ps1:13 char:1 + Get-Help another-func + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

我曾尝试将帮助注释放在函数之前和函数内部。

这是 Powershell 5 的回归,还是我做错了?目标是从脚本中获取基于每个函数的帮助输出。

更多细节:

> $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 0 10105 0

> [System.Environment]::OSVersion

Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 6.3.9600.0 Microsoft Windows NT 6.3.9600.0

最佳答案

功能的基于评论的帮助可以出现在三个位置之一:

  • 在函数体的开头。

  • 在函数体的末尾。

  • 在 Function 关键字之前。函数帮助的最后一行和函数关键字之间不能有超过一个空行。

关于此的 Microsoft 链接: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-5.0

尝试:

function a-func {
}
function another-func {
<#
.Synopsis
Testing Get-Help
#>
}

将代码粘贴到 powershell ISE 中,突出显示函数并按 F8,然后在控制台 Pane 中运行以下命令:

PS> Get-Help another-func

**抱歉,如果有任何格式问题,请通过我的电话回答此问题

关于powershell - 有没有办法让 Powershell 5 的 Get-Help 解析当前脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30462518/

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