It must be something extremely simple but I just can't make Get-Help work from within my PowerShell script.
Get-Help myscript -Examples in PowerShell command window, I get perfect help message. However, Get-Help myscript -Examples in my PowerShell script, it runs as if that the -Examples is not specified -- the normal help is shown, instead of the examples help.UPDATE:
As @lit has suspect, the reason is that, I'm running Get-Help on the same script that is currently running.
I just want to show help message for for my script. Here is an example you can try out:
<#
.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.
Short answer: use Out-String as follows:
Get-Help $MyInvocation.InvocationName -Examples | Out-String
In detail:
myscript inwhen I call
Get-Help myscript -Examplesin my PowerShell script, it runs as if that the-Examplesis not specified
Get-Help Get-Help -Online:Because the
Get-Helpcmdlet generates aMamlCommandHelpInfoobject, not a string, you have to use a cmdlet that transforms the help topic content into a string, such asOut-StringorOut-File.
MamlCommandHelpInfo.cs for differences in using Get-Help from within a .ps1 script vs. PS prompt.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With