How do I get help messages to appear for my Powershell script parameters?

后端 未结 3 641
庸人自扰
庸人自扰 2020-12-07 11:24

I have a powershell script (setup.ps1), that we use as the entry point for our development environment setup scripts. It takes a parameter:

par         


        
3条回答
  •  臣服心动
    2020-12-07 11:50

    Apparently if you have a help header defined, you can just use a remark (#) behind the parameter (in this example: #The targets to run.):

    <#
    .SYNOPSIS
        .
    .DESCRIPTION
        .
    .PARAMETER Path
        The path to the .
    .PARAMETER LiteralPath
        Specifies a path to one or more locations. Unlike Path, the value of 
        LiteralPath is used exactly as it is typed. No characters are interpreted 
        as wildcards. If the path includes escape characters, enclose it in single
        quotation marks. Single quotation marks tell Windows PowerShell not to 
        interpret any characters as escape sequences.
    #>
    
    Param(
        [String]$Targets = "Help"   #The targets to run.
    )
    

    Results in:

    PS C:\> Get-help .\Setup.ps1 -Detailed
    
    NAME
        C:\Setup.ps1
    
    SYNOPSIS
        .
    
    
    SYNTAX
        C:\Setup.ps1 [[-Targets] ] []
    
    
    DESCRIPTION
        .
    
    
    PARAMETERS
        -Targets 
            The targets to run.
    

提交回复
热议问题