web-dev-qa-db-ja.com

PowerShellのコードをどのようにコメントアウトしますか?

PowerShell(1.0または2.0)のコードをどのようにコメントアウトしますか?

883
labyrinth

PowerShell V1には、それ以降のテキストをコメントにするための#しかありません。

# This is a comment in Powershell

PowerShell V2では、<# #>をブロックコメント、より具体的にはヘルプコメントに使用できます。

#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 ([email protected])
    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
{}

.SYNOPSISおよび.*について詳しくは、 about_Comment_Based_Help を参照してください。

注意:これらの関数コメントはGet-Help CmdLetによって使用され、キーワードFunctionの前、またはコード自体の前後に{}内に置くことができます。

1179
JPBlanc

あなたはこのようなハッシュマークを使います

# This is a comment in Powershell

ウィキペディアには、いくつかの一般的な言語でコメントを作成する方法を追跡するための優れたページがあります。

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)#コメント

95
adamleerich

それは#です。

特殊文字については、PowerShell - 特殊文字とトークンを参照してください。

38
falcojr

単一行コメントは ハッシュ記号 で始まり、#の右側にあるものはすべて無視されます。

# Comment Here

PowerShell 2.0以降では、複数行のブロックコメントを使用できます。

<# 
  Multi 
  Line 
#> 

ブロックコメントを使用して、コマンド内にコメントテキストを埋め込むことができます。

Get-Content -Path <# configuration file #> C:\config.ini

注:PowerShellはタブ補完 をサポートしているため 、コメントの前にSpace + TABをコピーして貼り付けることに注意する必要があります。

30
Alexander

ここに

# Single line comment in Powershell

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

PowerShell ISEであなたはヒットすることができます Ctrl+J スニップの開始メニューを開き、コメントブロックを選択します。

enter image description here

13
Martin Brandl

あなたは作ることができます:

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

 <#
    for more lines
    ...
    ...
    ...
    ..
    .
 #>
3
Mister X CT