Menu
CoddyTech

Comments

Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 3 of 28.

A comment is text in a script that PowerShell does not run. Comments explain the code to the people who read it.

A line comment starts with #. Everything after # on that line is skipped, so a comment can also follow code on the same line:

# Greet the team
Write-Output "Hi team"  # printed first

A block comment starts with <# and ends with #>, and it can cover many lines:

<#
  Weekly cleanup script
  Runs every Monday
#>
Write-Output "Cleanup started"

This prints only Cleanup started. Putting # in front of a line of code is also how you switch that line off without deleting it.

challenge icon

Challenge

Beginner

The script prints a debug line that should not be in the report. Switch it off with a comment.

  1. Turn the line that prints Debug mode: on into a comment. Keep the other two lines as they are.

Your script prints:

Daily report
All systems normal

Try it yourself

<#
  Daily report script
#>
Write-Output "Daily report"
Write-Output "Debug mode: on"
Write-Output "All systems normal"
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in PowerShell Basics