powershell:基于评论的帮助

时间:2012-04-06 15:00:18

标签: powershell powershell-v2.0

我已经创建了一个小脚本来测试创建我自己的帮助PowerShell并收到错误:

  

Get-Help:无法找到主题“。\ testHelp.ps1”的帮助。在线:49   焦炭:15   + Get-Help<<<< @PSBoundParameters |更多       + CategoryInfo:ResourceUnavailable:(:) [Get-Help],HelpNotFoundException       + FullyQualifiedErrorId:HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

继承测试脚本:

<#
SYNOPSIS
retrieive a list of services from local and remote machines 
.DESCRIPTION
Retrieive services from local and remote machines and reports the following fields
.PARAMETER  Servers 
The Get-Service cmdlet gets objects that represent the services on a local computer or on a remote computer.
.EXAMPLE
PS C:\> Get-Something 'One value' 32
#>
param($computername="localhost")
Get-WmiObject -Class Win32_BIOS -ComputerName $computername

2 个答案:

答案 0 :(得分:4)

您似乎错过了.前面的.SYNOPSIS。您的帮助也说参数名为Servers,但参数块显示为$computername。虽然我认为它不会验证参数名称,但PowerShell对于帮助格式化是恰到好处非常挑剔。 : - )

结果是:

PS> Get-Content .\FuncHelp.ps1
<#
.SYNOPSIS
retrieive a list of services from local and remote machines 
.DESCRIPTION
Retrieive services from local and remote machines and reports the following fields
.PARAMETER  Servers 
The Get-Service cmdlet gets objects that represent the services on a local computer or on a remote computer.
.EXAMPLE
PS C:\> Get-Something 'One value' 32
#>
param($computername="localhost")
Get-WmiObject -Class Win32_BIOS -ComputerName $computername


PS> .\FuncHelp.ps1 -?

NAME
    C:\Users\hillr\FuncHelp.ps1

SYNOPSIS
    retrieive a list of services from local and remote machines


SYNTAX
    C:\Users\hillr\FuncHelp.ps1 [[-computername] <Object>] [<CommonParameters>]


DESCRIPTION
    Retrieive services from local and remote machines and reports the following fields


RELATED LINKS

REMARKS
    To see the examples, type: "get-help C:\Users\hillr\FuncHelp.ps1 -examples".
    For more information, type: "get-help C:\Users\hillr\FuncHelp.ps1 -detailed".
    For technical information, type: "get-help C:\Users\hillr\FuncHelp.ps1 -full".

答案 1 :(得分:0)

您可以使用名为PowerGui的免费Quest编辑器。你已经获得了一个带有高级帮助功能的代码片段(CTRL + I)。它为您提供了about_Comment_Based_Help

中提供的所有高级帮助关键字

您可以将<# #>用于您的功能或内部,但请注意帮助中的特殊字符,这会在复制/粘贴网络或PDF文档中的某些示例时出现错误。