powershell - powershell:基于注释的帮助

标签 powershell powershell-2.0

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

Get-Help : Cannot find Help for topic ".\testHelp.ps1". At line:49 char:15 + Get-Help <<<< @PSBoundParameters | more + 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

最佳答案

好像您缺少.前面的.SYNOPSIS。您的帮助还说该参数称为Servers,而param块说$computername。尽管我不认为PowerShell可以验证参数名称,但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".

关于powershell - powershell:基于注释的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045278/

相关文章:

powershell - TeamCity 远程 Powershell 访问突然被拒绝

powershell - 使用 Powershell 提取文件的前 50 个字节

powershell脚本忽略回车

powershell - 使用 PowerShell 的 Import-Csv cmdlet 将 CSV 类型快速转换为原始类型的方法?

Azure Runbook 命令

xml - 使用PowerShell,如何使用多个命名空间

xml - 使用 Powershell 编辑 .XML 文件,编码

powershell - 是否可以检查 Powershell 中是否给出了 -Verbose 参数?

powershell - 如何使用来自 sql 作业代理的默认凭据运行 powershell 脚本

powershell - PowerShell,当 “Wait-Event”触发时从 “Register-ObjectEvent -Action”返回吗?