#REQUIRES -Version 2.0
<#.SYNOPSISA brief description of the function or script. This keyword can be usedonly once in each topic..DESCRIPTIONA detailed description of the function or script. This keyword can beused only once in each topic..NOTESFile Name : xxxx.ps1Author : J.P. Blanc (jean-paul_blanc@silogix-fr.com)Prerequisite : PowerShell V2 over Vista and upper.Copyright 2011 - Jean Paul Blanc/Silogix.LINKScript posted over:http://silogix.fr.EXAMPLEExample 1.EXAMPLEExample 2#>Function blabla{}
# Single line comment in PowerShell
<#--------------------------------------Multi-line comment in PowerShell V2+--------------------------------------#>
# Get all Windows Service processes <-- one line comment, it starts with '#'Get-Process -Name *host*
Get-Process -Name *host* ## You could put as many ### as you want, it does not matter
Get-Process -Name *host* # | Stop-Service # Everything from the first # until end of the line is treated as comment
Stop-Service -DisplayName Windows*Update # -WhatIf # You can use it to comment out cmdlet switches
多行注释
<#Everyting between '< #' and '# >' istreated as a comment. A typical use case is for help, see below.
# You could also have a single line comment inside the multi line comment block.# Or two... :)
#>
<#.SYNOPSISA brief description of the function or script.This keyword can be used only once in each topic.
.DESCRIPTIONA detailed description of the function or script.This keyword can be used only once in each topic.
.NOTESSome additional notes. This keyword can be used only once in each topic.This keyword can be used only once in each topic.
.LINKA link used when Get-Help with a switch -OnLine is used.This keyword can be used only once in each topic.
.EXAMPLEExample 1You can use this keyword as many as you want.
.EXAMPLEExample 2You can use this keyword as many as you want.#>
嵌套多行注释
<#Nope, these are not allowed in PowerShell.
<# This will break your first multiline comment block... #>...and this will throw a syntax error.#>
在代码嵌套多行注释中
<#The multi line comment opening/closecan be also used to comment some nested codeor as an explanation for multi chained operations..#>Get-Service | <# Step explanation #>Where-Object { $_.Status -eq [ServiceProcess.ServiceControllerStatus]::Stopped } |<# Format-Table -Property DisplayName, Status -AutoSize |#>Out-File -FilePath Services.txt -Encoding Unicode
边缘情形
# Some well written scriptexitWriting something after exit is possible but not recommended.It isn't a comment.Especially in Visual Studio Code, these words baffle PSScriptAnalyzer.You could actively break your session in VS Code.