gpt4 book ai didi

powershell - powershell:基于注释的帮助

转载 作者:行者123 更新时间:2023-12-03 00:54:22 27 4
gpt4 key购买 nike

我创建了一个小脚本来测试创建自己的基于帮助的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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com