基于注释的帮助的正确语法.EXAMPLE

Chr*_*ton 5 powershell

根据 Powershell 帮助文件 (Get-Help about_comment_based_help) 中的信息,以下代码应该有效:

<#
    .EXAMPLE
        PS C:\> .\help_test.ps1
#>
Run Code Online (Sandbox Code Playgroud)

运行Get-Help .\help_test.ps1 -full时的预期输出应该是:

PS C:\Users\cbarton\Desktop\github\Powershell> Get-Help .\help_test.ps1 -full

NAME
    C:\Users\cbarton\Desktop\github\Powershell\help_test.ps1

SYNOPSIS


SYNTAX
    C:\Users\cbarton\Desktop\github\Powershell\help_test.ps1 [<CommonParameters>]


DESCRIPTION


PARAMETERS
    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\> .\help_test.ps1







RELATED LINKS
Run Code Online (Sandbox Code Playgroud)

然而,根据我的经验,我无法以同样的方式显示我的示例。相反,示例的命令部分与路径连接,并删除了所有空格。

OUTPUTS

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>.\help_test.ps1
Run Code Online (Sandbox Code Playgroud)

是我做错了什么,还是所有 Microsoft 示例都错了?

PS C:\Users\cbarton\Desktop\github\Powershell> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1012
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1012
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Run Code Online (Sandbox Code Playgroud)

mkl*_*nt0 4

PowerShell总是会.EXAMPLE在基于注释的帮助块内重新格式化第一行(非空白) 。

事实上,您甚至不需要PS C:\>自己指定- 它会自动添加,这样您就可以得到相同的结果:

<#
    .EXAMPLE
    .\help_test.ps1
#>
Run Code Online (Sandbox Code Playgroud)

但是,会保留显式指定的定义提示字符串,例如。C:\path\to>

然而,隐含的或自定义的提示字符串总是与行的其余部分连接,并删除前导空格,因此>.

鉴于 PowerShell 的真实(默认)提示符后面带有>一个空格,因此应该修复该差异。

另一个有问题的方面是,即使在类Unix平台上, PowerShell Core在示例中也默认为(即,它使用Windows文件系统路径),这可能会令人困惑。PS C:\>

我已在 GitHub 上报告了这些问题