根据Powershell帮助文件中的信息(Get-Help about_comment_based_help),以下代码应该有效:
<#
.EXAMPLE
PS C:\> .\help_test.ps1
#>
运行 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
但是根据我的经验,我无法以相同的方式显示我的示例。相反,示例的命令部分与路径连接,删除了所有空格。
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\>.\help_test.ps1
我做错了什么,或者所有的微软示例都错了?
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
答案 0 :(得分:4)
PowerShell 总是在基于注释的帮助块中.EXAMPLE
之后重新格式化第一行(非空白)行。
事实上,您甚至不需要自己指定PS C:\>
- 它会自动添加,以便您获得相同的结果:
<#
.EXAMPLE
.\help_test.ps1
#>
但是,保留了明确指定的自定义提示字符串,例如C:\path\to>
。
但是,隐含或自定义提示字符串与前导空格已移除的其余部分连接在一起,因此永远不会一个空格>
。
鉴于PowerShell的真实(默认)提示在>
之后只有一个空格,因此应该修正差异。
另一个有问题的方面是PowerShell Core 在示例中默认为PS C:\>
,即使在类似 Unix 的平台上(即,它使用 Windows < / em> filesystem path),这可能令人困惑。