自己的 PowerShell 手册中没有路径的语法

Syntax without path in own PowerShell manual

我为我的 PowerShell 脚本写了一篇关于 this site 的帮助 header。 该脚本存储在添加到 env:path 变量的目录中。 当我调用 help myscript 时返回帮助,但 SYNTAX 部分显示完整路径。是否可以只显示脚本名称?该名称已显示完整路径。

SYNTAXautogenerated 基于评论的帮助:

AUTOGENERATED CONTENT

The name, syntax, parameter list, parameter attribute table, common parameters, and remarks are automatically generated by the Get-Help cmdlet.

...

Syntax:

The Syntax section of the help topic is generated from the function or script syntax. To add detail to the help topic syntax, such as the .NET Framework type of a parameter, add the detail to the syntax. If you do not specify a parameter type, the "Object" type is inserted as the default value.

理论上,可以使用基于 XML 的帮助和 .EXTERNALHELP 关键字覆盖它:

.EXTERNALHELP

Specifies an XML-based help file for the script or function.

The ExternalHelp keyword is required when a function or script is documented in XML files. Without this keyword, Get-Help cannot find the XML-based help file for the function or script.

The ExternalHelp keyword takes precedence over other comment-based help keywords. If ExternalHelp is present, Get-Help does not display comment-based help, even if it cannot find a help topic that matches the value of the ExternalHelp keyword.

示例:

#  .ExternalHelp C:\MyScripts\Update-Month-Help.xml

param ([string]$InputPath, [string]$OutPutPath)
function Get-Data { }

不幸的是,我无法让它工作 - PowerShell 识别 ExternalHelp 关键字(结果 with/without 不同),但不会加载基于 XML 的帮助。

这是我试过的:

TestExtHelp.ps1:

#.ExternalHelp TestExtHelp.xml
Param()
Write-Host 'Hello, World!'

TestExtHelp.xml:

<?xml version="1.0" encoding="utf-8"?>

<helpItems schema="maml">
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
    <command:syntax>
        <command:syntaxItem>
            <maml:name>Set-Test</maml:name>
            <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="0">
                <maml:name>InputObject</maml:name>
                <maml:description>
                    <maml:para>output from get-test</maml:para>
                </maml:description>
                <command:parameterValue required="true" variableLength="false">Object</command:parameterValue>
            </command:parameter>
        </command:syntaxItem>
    </command:syntax>
</command:command>
</helpItems>

我也试过制作 TestExtHelp 模块和不同的路径组合,但没有成功。

参考资料