0

HowTo: Erstellen einer Hilfe in PowerShell Skripten

Um eine schnelle Hilfe für PowerShell Skripte zu erhalten kann das cmdlet „get-help“ verwendet werden. Dieser Beitrag erklärt wie die Hilfefunktion auch in eigenen Skripten verwendet werden kann. Das vorgehen dazu ist relativ einfach. Das Skript muss einen entsprechenden Kommentarblock enthalten. Der Kommentarblock wir durch „<#“ eingeleitet und durch „#>“ beendet.  Der Kommentarblock enthält durch einen „.“ eingeleitete Schlüsselwörter.

Kommentarblock:

<#

.SYNOPSIS

Kurzbeschreibung des Skriptes oder dessen Funktion

.EXAMPLE

Beispiel für den Aufruf des Skriptes

#>

Folgende Schlüsselwörter werden durch „get-help“ verarbeitet:

Help tag name Help tag description
.Synopsis A very brief description of the function. It begins with a verb and tells the user what the function does. It does not include the function name or how the function works. The function synopsis appears in the SYNOPSIS field of all help views.
.Description Two or three full sentences that briefly list everything that the function can do. The description begins with „The <function name> function….“ If the function can get multiple objects or take multiple inputs, use plural nouns in the description. The description appears in the DESCRIPTION field of all Help views.
.Parameter Brief and thorough. Describe what the function does when the parameter is used. And what legal values are for the parameter. The parameter appears in the PARAMETERS field only in Detailed and Full Help views.
.Example Illustrate use of function with all its parameters. First example is simplest with only the required parameters. Last example is most complex and should incorporate pipelining if appropriate. The example appears only in the EXAMPLES field in the Example, Detailed, and Full Help views.
.Inputs Lists the .NET Framework classes of objects the function will accept as input. There is no limit to the number of input classes you may list. The inputs Help tag appears only in the INPUTS field in the Full Help view.
.Outputs Lists the .NET Framework classes of objects the function will emit as output. There is no limit to the number of output classes you may list. The outputs Help tag appears in the OUTPUTS field only in the Full Help view.
.Notes Provides a place to list information that does not fit easily into the other sections. This can be special requirements required by the function, as well as author, title, version, and other information. The notes Help tag appear in the NOTES field only in the Full help view.
.Link Provides links to other Help topics and Internet Web sites of interest. Because these links appear in a command window, they are not direct links. There is no limit to the number of links you may provide. The links appear in the RELATED LINKS field in all Help views.

Quelle:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/01/07/hey-scripting-guy-january-7-2010.aspx?Redirected=true

Codebeispiel:

 

<#

    .SYNOPSIS

     Dieses Skript gibt meine als Parameter übergebene Eingabe mit dem Zusatz „Aufruf“ aus

    .EXAMPLE

     Beispiel für den Aufruf des Skriptes:

    grab-input „meiner Hilfe“

#>

param ($string)

Write-Host „Aufruf $string

beuermann

Schreibe einen Kommentar