Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add documentation to custom methods (ScriptMethod)

A custom PowerShell script or function can be documented with a standard comment at the beginning of its body:

function wellDocumented {
   <#
       .SYNOPSIS
       A well documented function
       .DESCRIPTION
       "Be verbose in documentation" - someone
       .PARAMETER foo
        should be 42 or 15, but not more
    #>
    param( [int]$foo )
    <# ... #>
}

Get-Help wellDocumented returns some nice information then. But how can I document custom ScriptMethods in custom objects? The following does not work:

$myClass | add-member -memType ScriptMethod -Name "Foo" -Value {
    <#
        .SYNOPSIS
        Something - but brief
        .DESCRIPTION
        Something
    #>
    <# ... #>
}

Is there some standard way to document your ScriptMethods?

like image 498
Sh4pe Avatar asked Oct 29 '14 11:10

Sh4pe


1 Answers

You can write your script method as a separate function first (like you did with wellDocumented) then pass the function as the scriptblock:

$myClass | add-member -memType ScriptMethod -Name "Foo" -Value ${function:wellDocumented}

You still can't call Get-Help $myClass.Foo, but you can call Get-Help wellDocumented.

In my testing I was not able to get help on a method.

like image 53
briantist Avatar answered Nov 20 '22 18:11

briantist