【问题标题】:powershell: comment based helppowershell:基于评论的帮助
【发布时间】:2012-04-20 04:15:26
【问题描述】:

我创建了一个小脚本来测试创建我自己的基于帮助的 powershell,但我收到了错误:

获取帮助:找不到主题“.\testHelp.ps1”的帮助。在线:49 字符:15 + 获取帮助

测试脚本如下:

<#
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

【问题讨论】:

    标签: powershell powershell-2.0


    【解决方案1】:

    您似乎缺少.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".
    

    【讨论】:

    • 我放了一个 .在前面,仍然是同样的问题
    • Get-Help 是否被代理?尝试运行到Get-Command Get-Help | Format-List * 以查看Get-Help 来自哪个模块。
    • powershell 脚本也通过安全性不喜欢的 UNC 路径运行。复制到本地,问题解决了。
    【解决方案2】:

    您可以使用名为 PowerGui 的免费 Quest 编辑器。您已经获得了具有高级帮助的功能的 a sn-p (CTRL+I)。它为您提供了您可以在about_Comment_Based_Help中找到的所有高级帮助关键字

    您可以将&lt;# #&gt; 放在您的函数之前或内部,但请注意帮助中的特殊字符,这会在从网络或 PDF 文档中复制/粘贴一些示例时导致我出现一些错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-25
      • 2014-08-16
      • 1970-01-01
      • 2018-07-17
      • 2013-07-10
      • 2011-05-11
      • 2012-07-22
      • 1970-01-01
      相关资源
      最近更新 更多