如何在 PowerShell 中注释掉代码?

如何注释掉 PowerShell(1.0 或 2.0)中的代码?

答案

# This is a comment in Powershell
#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
{}
# This is a comment in Powershell
# Comment Here
<# 
  Multi 
  Line 
#>
Get-Content -Path <# configuration file #> C:\config.ini
# Single line comment in Powershell

<# 
--------------------------------------
Multi-line comment in PowerShell V2+ 
-------------------------------------- 
#>

在 PowerShell ISE 中,您可以按 Ctrl + J打开 “ 开始截图”菜单,然后选择 “ 注释” 块

在此处输入图片说明

(Some basic code) # Use "#" after a line and use:

 <#
    for more lines
    ...
    ...
    ...
    ..
    .
 #>