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?
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.
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