Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment Based Help not displayed in Powershell

I am trying to implement Comment Based Help as described here with Powershell 5.1 on Windows Server 2016.

The script I am using is called blah.ps1:

<#
.DESCRIPTION
blah blah
#>
function Blahblah
{
}

In Powershell, I can load the script:

.\blah.ps1

But when I ask for help on this function using:

Get-Help Blahblah

Powershell only reports an error:

Get-Help : Get-Help could not find Blahblah in a help file in this session. To download updated help topics type: "Update-Help". To get help online, search for the help topic in the TechNet library at http://go.microsoft.com/fwlink/?LinkID=107116.
At line:1 char:1
+ Get-Help Blahblah
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
    + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

I am assuming that Get-Help can be used with the custom help comments. What am I missing?

like image 724
helb Avatar asked Jul 15 '26 08:07

helb


2 Answers

Import the script as a module instead of running it.

Import-Module .\blah.ps1
like image 181
G42 Avatar answered Jul 17 '26 16:07

G42


While declaring the function, including the help immediately after the function header, saving it in a module, and importing the module is probably the best way to handle it, you can make your script's help available to Get-Help by ensuring that...

  1. the function name and the file name match (which means one function per file), and...
  2. ensuring that the script file is in a directory that is in $env:PATH.

The help for the function can be declared before the function itself is, provided that there is no more than one blank line between the help's closing #> and the beginning of the function declaration.

See Get-Help about_Comment_Based_Help in either the PowerShell help or the linked Microsoft documentation.

like image 45
Jeff Zeitlin Avatar answered Jul 17 '26 17:07

Jeff Zeitlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!