How do you comment out code in PowerShell?

前端 未结 10 1555
傲寒
傲寒 2020-12-12 08:59

How do you comment out code in PowerShell (1.0 or 2.0)?

10条回答
  •  醉梦人生
    2020-12-12 09:35

    In PowerShell V1 there's only # to make the text after it a comment.

    # This is a comment in Powershell
    

    In PowerShell V2 <# #> can be used for block comments and more specifically for help comments.

    #REQUIRES -Version 2.0
    
    <#
    .SYNOPSIS
        A brief description of the function or script. This keyword can be used
        only once in each topic.
    .DESCRIPTION
        A detailed description of the function or script. This keyword can be
        used only once in each topic.
    .NOTES
        File Name      : xxxx.ps1
        Author         : J.P. Blanc (jean-paul_blanc@silogix-fr.com)
        Prerequisite   : PowerShell V2 over Vista and upper.
        Copyright 2011 - Jean Paul Blanc/Silogix
    .LINK
        Script posted over:
        http://silogix.fr
    .EXAMPLE
        Example 1
    .EXAMPLE
        Example 2
    #>
    Function blabla
    {}
    

    For more explanation about .SYNOPSIS and .* see about_Comment_Based_Help.

    Remark: These function comments are used by the Get-Help CmdLet and can be put before the keyword Function, or inside the {} before or after the code itself.

提交回复
热议问题