Comment-based help lets you add instructions inside your PowerShell scripts. It helps others understand what your script or function does.
You write a script and want to explain what it does.
You create a function and want to show how to use it.
You want to provide examples inside your script for users.
You want to add details about parameters your script accepts.
You want to make your script easier to maintain and share.
Syntax
PowerShell
<#
.SYNOPSIS
Short description of the script or function.
.DESCRIPTION
Longer explanation.
.PARAMETER ParameterName
Description of a parameter.
.EXAMPLE
Example of how to use the script or function.
#>
Use <# to start and #> to end the comment-based help block.
Each section starts with a dot and uppercase keyword like .SYNOPSIS or .PARAMETER.
Examples
This example shows a simple synopsis for a script that prints a message.
PowerShell
<#
.SYNOPSIS
Prints Hello World.
#>
Write-Output "Hello World"
This example shows help for a function with parameters and an example usage.
PowerShell
<#
.SYNOPSIS
Adds two numbers.
.PARAMETER a
First number.
.PARAMETER b
Second number.
.EXAMPLE
Add-Numbers -a 3 -b 5#>function Add-Numbers {
param($a, $b)
$a + $b
}
Sample Program
This script defines a function with comment-based help. It greets the user by name.
PowerShell
<#
.SYNOPSIS
Greets a user by name.
.DESCRIPTION
This function takes a name and prints a greeting message.
.PARAMETER Name
The name of the person to greet.
.EXAMPLE
Greet-User -Name "Alice"#>function Greet-User {
param(
[string]$Name
)
Write-Output "Hello, $Name!"
}
Greet-User -Name "Alice"
OutputSuccess
Important Notes
Use comment-based help to make your scripts self-explanatory.
You can view the help by running Get-Help FunctionName in PowerShell.
Keep descriptions short and clear for easy understanding.
Summary
Comment-based help adds useful instructions inside scripts.
It uses special comment blocks with sections like SYNOPSIS and PARAMETER.
It helps users understand and use your scripts correctly.
Practice
(1/5)
1. What is the main purpose of comment-based help in a PowerShell script?
easy
A. To provide instructions and details about the script for users
B. To make the script run faster
C. To encrypt the script content
D. To automatically fix script errors
Solution
Step 1: Understand what comment-based help is
Comment-based help is written inside scripts as special comments to explain what the script does and how to use it.
Step 2: Identify the purpose of these comments
The comments help users understand the script, not affect performance or security.
Final Answer:
To provide instructions and details about the script for users -> Option A
Quick Check:
Comment-based help = user instructions [OK]
Hint: Help comments explain script usage, not execution speed [OK]
Common Mistakes:
Thinking help comments speed up scripts
Confusing help with encryption
Assuming help fixes errors automatically
2. Which of the following is the correct way to start a comment-based help block in PowerShell?
easy
A. <#
B. ##
C.
D. #>
Solution
Step 1: Recall PowerShell comment syntax
PowerShell uses <# and #> to start and end block comments, which are used for comment-based help.
Step 2: Identify the correct start marker
The block comment starts with <# and ends with #>. Other options are not valid for block comments.
Final Answer:
<# -> Option A
Quick Check:
Block comment start = <# [OK]
Hint: Block comments start with <# and end with #> [OK]
Common Mistakes:
Using ## which is line comment, not block
Confusing with HTML comments
Using #> alone as start
3. Given this comment-based help snippet inside a script:
<#
.SYNOPSIS
Shows a greeting message
.PARAMETER Name
The name to greet
#>
function Greet-User {
param([string]$Name)
"Hello, $Name!"
}
What will Get-Help Greet-User display under the SYNOPSIS section?
medium
A. No help available
B. The name to greet
C. Hello, $Name!
D. Shows a greeting message
Solution
Step 1: Identify the SYNOPSIS section content
The SYNOPSIS section contains the short description: "Shows a greeting message".
Step 2: Understand Get-Help output
Get-Help shows the SYNOPSIS text exactly as written under that section.
Final Answer:
Shows a greeting message -> Option D
Quick Check:
SYNOPSIS text = Shows a greeting message [OK]
Hint: SYNOPSIS shows short script description in Get-Help [OK]
Common Mistakes:
Confusing PARAMETER text with SYNOPSIS
Expecting function output as help text
Assuming no help shows by default
4. You wrote this comment-based help block but Get-Help shows no information:
#
.SYNOPSIS
Prints date
.PARAMETER Format
Date format string
#>
function Show-Date {
param([string]$Format)
Get-Date -Format $Format
}
What is the error preventing help from showing?
medium
A. PARAMETER section misspelled
B. Function name missing in help
C. Missing starting <# for block comment
D. No SYNOPSIS section present
Solution
Step 1: Check comment block delimiters
The help block starts with # but must start with <# to be recognized as block comment.
Step 2: Understand Get-Help parsing
Without <# at start, the help block is ignored, so no help shows.
Final Answer:
Missing starting <# for block comment -> Option C
Quick Check:
Block comment start missing = no help shown [OK]
Hint: Block comments must start with <# and end with #> [OK]
Common Mistakes:
Using # instead of <# to start block comment
Misspelling PARAMETER keyword
Thinking function name is required in help block
5. You want to add comment-based help to a script with two parameters: Path (string) and Recurse (switch). Which is the correct way to document these parameters inside the help block?
hard
A.
<#
.PARAMETER Path
The file or folder path
.PARAMETER Recurse
The file or folder path
#>
B.
<#
.PARAMETER Path
The file or folder path
.PARAMETER Recurse
Switch to include subfolders
#>
C.
<#
.PARAMETER Path
Switch to include subfolders
.PARAMETER Recurse
The file or folder path
#>
D.
<#
.PARAMETER Path
The file or folder path
.PARAMETER Recurse
No description needed
#>
Solution
Step 1: Match parameter names with correct descriptions
Path is a string for file/folder path; Recurse is a switch to include subfolders.
Step 2: Verify correct PARAMETER sections
<#
.PARAMETER Path
The file or folder path
.PARAMETER Recurse
Switch to include subfolders
#>
correctly documents Path and Recurse with matching descriptions.
Final Answer:
Correct PARAMETER descriptions for Path and Recurse -> Option B
Quick Check:
Parameter names match descriptions [OK]
Hint: Match parameter names exactly with clear descriptions [OK]
Common Mistakes:
Swapping descriptions between parameters
Repeating same description for different params
Leaving out descriptions for parameters
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.