PowerShell Cmdlet Help

 

Help in a custom cmdlet is a simple comment block at the beginning of a function, or at the beginning of a PowerShell script file.

Windows PowerShell Help is covered in the following article: PowerShell Help. and creating a script in this: how do I create a Windows PowerShell script.

As a template for your own help you can use the cmdlet snippet in the PowerShell ISE, this can be inserted with Ctrl+J and "Cmdlet (extended function)":

For more information about snippet, see: Powershell ISE - Snippet

Comment block - get-help

Help in Windows PowerShell can be stored before the start of a function within the comment block:(<#..#>).

<#
.Synopsis
kurze Beschreibung
#>
function MyFunction ($param1, $param2)
{
    
}

Attention: The help information must not have more than one line of space between the comment block and the function following it.

.Synopsis is a short description

get-help myFunction

PS P:\> get-help MyFunction

NAME
    MyFunction
    
SYNOPSIS
    kurze Beschreibung
    
    
SYNTAX
    MyFunction [[-param1] <Object>] [[-param2] <Object>] [<CommonParameters>]
    
    
DESCRIPTION
    

RELATED LINKS

REMARKS
    To see the examples, type: "get-help MyFunction -examples".
    For more information, type: "get-help MyFunction -detailed".
    For technical information, type: "get-help MyFunction -full".

PowerShell tries to create help text based on the information in the script, for example, the Syntax section is automatically output by the available parameters. Other areas, such as the short description .synopsis must of course be specified in the script.

more comment keywords

cmdlet snippet in PowerShell ISE editor (Ctrl +J) PowerShell passing of variables (Param )

<#
.Synopsis
   Short description
.DESCRIPTION
   Long description
.EXAMPLE
   Example of how to use this cmdlet
.EXAMPLE
   Another example of how to use this cmdlet
#>
Keyword Description
.Synopsis Short description
.DESCRIPTION Long description
.Parameter Parameter description, can also be written directly in front of the respective parameter (leading #)
.EXAMPLE Example: can also be used multiple times

Hilfe zu den jeweiligen Parametern

function Verb-Noun
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([int])]
    Param
    (
        # Help description for Param1
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Param1,

        # Help description for Param2
        [int]
        $Param2
    )

...

If a comment is added above a parameter, it is automatically interpreted as help for that parameter.

Call get-help and display: 

[+]
PS P:\> get-help Verb-Noun -Full

NAME
    Verb-Noun
    
SYNTAX
    Verb-Noun [-Param1] <Object> [-Param2 <int>]  [<CommonParameters>]
    
    
PARAMETERS
    -Param1 <Object>
        
        Required?                    true
        Position?                    0
        Accept pipeline input?       true (ByPropertyName)
        Parameter set name           (All)
        Aliases                      None
        Dynamic?                     false
        
    -Param2 <int>
        
        Required?                    false
        Position?                    Named
        Accept pipeline input?       false
        Parameter set name           (All)
        Aliases                      None
        Dynamic?                     false
        
    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). 
    
    
INPUTS
    System.Object
    
    
OUTPUTS
    System.Int32
    
    
ALIASES
    None
    

REMARKS
    None

Call get-help and display for a specific parameter:

PS C:\Users\LiBe> get-help Verb-Noun -Parameter param1

-Param1 <Object>
    
    Required?                    true
    Position?                    0
    Accept pipeline input?       true (ByPropertyName)
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false
    
positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

created by Bernhard | published: 2022-05-02 Übersetzung Deutsch |🔔 | Comments:0

Questions / Comments


By continuing to browse the site, you agree to our use of cookies. More Details