PowerShell Gethelp仅返回script.ps1文件的文件名



我必须在这里缺少简单的东西。

我已经在我的PS1文件中的一个功能中实现了一些帮助注释:

<#
.SYNOPSIS
Adds a file name extension to a supplied name.
.DESCRIPTION
Adds a file name extension to a supplied name.
Takes any strings for the file name or extension.
.PARAMETER Name
Specifies the file name.
.PARAMETER Extension
Specifies the extension. "Txt" is the default.
.INPUTS
None. You cannot pipe objects to Add-Extension.
.OUTPUTS
System.String. Add-Extension returns a string with the extension or file name.
.EXAMPLE
C:PS> extension -name "File"
File.txt   
#>

直接在功能之后运行get-Help"函数名称"并通过PowerShell窗口运行PS1脚本时,我会得到正确的响应。

现在,我正在使用此处的代码:http://ben.neise.co.uk/scriptdocumentationinmarkdown/

这应该从我的脚本文件中的帮助注释中生成一些标记文档。运行时,我会收到错误:

GenerateScriptDocumentationInMarkdown : Inline help not found for script C:****testScript.ps1

(generates documentation in markdown是函数名称)。

行错误是我用一些文件播放来调用函数的行:

GenerateScriptDocumentationInMarkdown -SourceScriptFolder "C:****testScripts"  -DocumentationOutputFolder "C:****GeneratingMarkdownFileTest" -DocumentationIndexPath "C:****GeneratingMarkdownFileTestscripts_Ps1.markdown"

'内联帮助未找到脚本的错误'错误是什么意思?

编辑

这是脚本中失败的地方:

 $help = Get-Help $script.FullName -ErrorAction "SilentlyContinue"       
        if ($help.getType().Name -eq "String"){
            # If there's no inline help in the script then Get-Help returns a string
            Write-Error -Message "Inline help not found for script $($script.FullName)"
        } else {

注意条件检查.NAME是否为字符串。在我看,我的脚本上的求助是没有返回应该的。

我希望'get-help {pathtofile.ps1}'会返回脚本文件中的所有注释,但是它返回的只是脚本名称?

多亏了@bacon位。

当评论在功能中时,我正在误解生成函数的作用。我要做的是循环浏览脚本文件中的函数,然后在函数上运行逻辑而不是整个文件。

因此,仅在此文件中获取功能:

 $currentFunctions = Get-ChildItem function:
        # dot source your script to load it to the current runspace
        . $script.FullName
        $scriptFunctions = Get-ChildItem function: | Where-Object { $currentFunctions -notcontains $_ }
        $scriptFunctions | ForEach-Object {
              & $_.ScriptBlock
        }

然后循环遍历并像这样运行逻辑:

$scriptFunctions | ForEach-Object {
        $fullName = $_.Name
        $help = Get-Help $fullName -ErrorAction "SilentlyContinue" 
.
.
.

最新更新