它必须非常简单,但是我无法在我的PowerShell脚本中使Get-Help
正常工作。
Get-Help myscript -Examples
时,会得到完美的帮助消息。但是,Get-Help myscript -Examples
时,它的运行就像未指定-Examples
一样-显示常规帮助,而不是示例帮助。更新:
@lit怀疑,原因是,我在当前正在运行的同一脚本上运行Get-Help。
我只想显示有关我的脚本的帮助消息。这是您可以尝试的示例:
<#
.SYNOPSIS
Calculates the number of possible passwords
.DESCRIPTION
Calculates the number of possible passwords based
on the input so you will know the actual number before
you proceed to create your dictionary file.
.PARAMETER CharacterSet
Specifies the characters (letters, numbers, symbols) that
need to be included. Parameter is mandatory.
.PARAMETER MinCharacters
Specifies the minimum characters of the generated passwords.
Parameter is mandatory.
.PARAMETER MaxCharacters
Specifies the maximum characters of the generated passwords.
Parameter is mandatory.
.PARAMETER IncludeCapital
Specifies whether or not to include upper case letters along with
the lower case letters.
.PARAMETER CapitalOnly
Specifies whether or not all lower case letters to be converted to
upper case letters.
.INPUTS
System.String. Get-PasswordNumber can accept a string value to
determine the CharacterSet parameter.
.OUTPUTS
System.Double. Get-PasswordNumber returns the number of passwords that
can be created.
.EXAMPLE
C:\PS> Get-PasswordNumber -CharacterSet "a,b,c,1,2,3,$,*,&" -MinCharacters 2 -MaxCharacters 5
66420
.EXAMPLE
C:\PS> Get-PasswordNumber -Characters "a,b,c,1,2,3,$,*,&" -MinCharacters 2 -MaxCharacters 5 -IncludeCapital
271440
.EXAMPLE
C:\PS> Get-PasswordNumber -Characters "a,b,c,1,2,3,$,*,&" -MinCharacters 2 -MaxCharacters 5 -CapitalOnly
66420
.EXAMPLE
C:\PS> Get-PasswordNumber -Characters alphabet -MinCharacters 2 -MaxCharacters 5
12356604
.LINK
PowerShell Module DictionaryFile
#>
param(
[switch]$IncludeCapital,
[switch]$CapitalOnly)
write-host program started.
if (!$CapitalOnly) {
Get-Help myscript
Get-Help myscript -Examples
}
write-host program ended.
答案 0 :(得分:1)
简短答案:按如下方式使用Out-String
:
Get-Help $MyInvocation.InvocationName -Examples | Out-String
详细信息:
myscript
当我在PowerShell脚本中调用
Get-Help myscript -Examples
时,它的运行就像未指定-Examples
Get-Help Get-Help -Online
中发现了一个纯真的(据称无关)笔记:因为
Get-Help
cmdlet生成了MamlCommandHelpInfo
对象,而不是字符串,则必须使用一个cmdlet来转换 帮助主题内容转换为字符串,例如Out-String
或Out-File
。
Get-Help
脚本和PS提示中使用.ps1
的差异,未能在MamlCommandHelpInfo.cs
中嗅到。