Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the Get-Help cmdlet to display comment-based help in the same format

Tags:

I am trying to use the Get-Help cmdlet to display comment-based help in the same format in which it displays the cmdlet help topics that are generated from XML files. The ability to do this is documented in about_Comment_based_Help on TechNet, but when I execute the get-help cmdlet against my script I only get the script name returned. Any help would be appreciated!

PS C:\Admin> Get-Help .\checksystem.ps1 -full
checksystem.ps1

checksystem.ps1 script:

function IsAlive {
        <#
        .DESCRIPTION
        Checks to see whether a computer is pingable or not.

        .PARAMETER computername
        Specifies the computername.

        .EXAMPLE
        IsAlive -computername testwks01

        .NOTES
        This is just an example function.
        #>


            param (
                $computername
            )
            Test-Connection -count 1 -ComputerName $computername -TimeToLive 5 |
            Where-Object { $_.StatusCode -eq 0 } |
            Select-Object -ExpandProperty Address
        }

IsAlive -computername 192.168.1.1
like image 444
Shaun Avatar asked Jan 12 '11 22:01

Shaun


People also ask

How do I get help from cmdlet?

The Get-Help cmdlet displays information about PowerShell concepts and commands, including cmdlets, functions, Common Information Model (CIM) commands, workflows, providers, aliases, and scripts. To get help for a PowerShell cmdlet, type Get-Help followed by the cmdlet name, such as: Get-Help Get-Process .

How do I show comments in PowerShell?

You can type a comment symbol # before each line of comments, or you can use the <# and #> symbols to create a comment block. All the lines within the comment block are interpreted as comments.

How do I use the Help command in PowerShell?

The Get-Help cmdlet displays information about Windows PowerShell concepts and commands, including cmdlets, functions, CIM commands, workflows, providers, aliases and scripts. To get help for a Windows PowerShell command, type `Get-Help` followed by the command name, such as: `Get-Help Get-Process`.

How do you write a help in PowerShell?

The Get-Help cmdlet displays the script and function help topics in the same format as it displays help for cmdlets, and all of the Get-Help parameters work on script and function help topics. PowerShell scripts can include a help topic about the script and help topics about each functions in the script.


1 Answers

It will work, but you are trying to run get help on the script. You have added the help to the function. If you dot source your script, and then type get-help isalive, you will see your help for the function.

. .\checksystem.ps1 ; get-help isalive -full
like image 113
Andy Schneider Avatar answered Oct 13 '22 23:10

Andy Schneider