Adding documentation to user 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 info. But how can I document custom ScriptMethod in custom objects? The following does not work:

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

Is there a standard way to document your ScriptMethods?

+8
source share
1 answer

You can write your script method as a separate function first (for example, you did with wellDocumented ), and then pass the function as a script block:

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

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

During testing, I could not get help using the method.

+1
source share

All Articles