このエントリーをはてなブックマークに追加


PowerShellスクリプトの複数行コメントアウト方法 <# .. #>

本記事は、PowerShellスクリプトを複数行コメントアウト化する方法を以下に記します。


関連記事

linux.just4fun.bizの記事です。

複数行をコメント化してみる

以下のスクリプトで複数行を <# .. #> でコメント化して実行してみます。

Write-Output "Windows 3.1"
Write-Output "Windows 95"
Write-Output "Windows 98"
Write-Output "Windows NT"
Write-Output "Windows 2000"
Write-Output "Windows Me"
Write-Output "Windows XP"
Write-Output "Windows Vista"
Write-Output "Windows 7"
Write-Output "Windows 8"
Write-Output "Windows 8.1"
Write-Output "Windows 10"

複数行コメント化前の実行結果

コメントする前の実行結果です。

PS D:\> .\tst.ps1
Windows 3.1
Windows 95
Windows 98
Windows NT
Windows 2000
Windows Me
Windows XP
Windows Vista
Windows 7
Windows 8
Windows 8.1
Windows 10

複数行コメント化後の実行結果

以下の様にコメントしました。

Write-Output "Windows 3.1"
<# Write-Output "Windows 95"
Write-Output "Windows 98"
Write-Output "Windows NT"
Write-Output "Windows 2000"
Write-Output "Windows Me"
Write-Output "Windows XP"
Write-Output "Windows Vista"
Write-Output "Windows 7"
Write-Output "Windows 8"
Write-Output "Windows 8.1" #>
Write-Output "Windows 10"

上記例では、各行の先頭と末尾に <#と#>を記述しました。
以下の様に別行に書いても同様の動作をします。

Write-Output "Windows 3.1"
<#
Write-Output "Windows 95"
<省略>
Write-Output "Windows 8.1"
#>
Write-Output "Windows 10"

コメント化の実行結果です。

PS D:\> .\tst2.ps1
Windows 3.1
Windows 10

以上、PowerShellで複数行をコメント化する記述方法の紹介でした。



添付ファイル: filetst.ps1 435件 [詳細] filetst2.ps1 445件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-03-13 (日) 21:57:16