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 firstA 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
BeginnerThe script prints a debug line that should not be in the report. Switch it off with a comment.
- Turn the line that prints
Debug mode: oninto a comment. Keep the other two lines as they are.
Your script prints:
Daily report
All systems normalTry it yourself
<#
Daily report script
#>
Write-Output "Daily report"
Write-Output "Debug mode: on"
Write-Output "All systems normal"
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in PowerShell Basics
5Project: Password Checker
Project OverviewLength Check