Like any other scripting or programming language, PowerShell provides comments to help make the scripts more readable and maintainable.
Below is a list of comments that are supported by Microsoft PowerShell with Examples.
Single-Line Comment:
Single-Line comments in PowerShell start with # hash sign.
Example:# Example of Single Line Comment in PowerShell $no = 20 # This is also a Single Line Comment.
Multi-Line Comment:
Multi-line commands start with <# and ends with #>
Example:<# This is an example of Multi-line comment in PowerShell. You can add as many lines as you want. #>
Let's see a practical usage of both these types of comments with a real-world example.

<#
PowerShell script to convert CSV to PSV
Author: Code2care.org
Version: 1.1
Today's date: 2023-07-21
#>
# Input file (CSV) and output file (PSV) paths
$csvFile = "2023_data.csv"
$psvFile = "2023_data.psv"
# Import the CSV data using Import-Csv
$csvData = Import-Csv -Path $csvFilePath
# Convert each row to a PSV-formatted string
$psvData = $csvData | ForEach-Object {
# Join the properties with the pipe (|) separator
$psvRow = $_.Name, $_.Age, $_.Location -join "|"
# Output the PSV-formatted string
$psvRow
}
# Save the PSV data to the output file
$psvData | Out-File -FilePath $psvFilePath
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!