How to comment out code in Powershell, we have to comment the text inside the script to descript the code so that others understand the function of the code, here is the simple symbol we use in Powershell to comment out.
If you are a beginner to Powershell scripting and looking for how to comment out the code? in most shell scripting languages the hash # symbol is used for commenting code in the script, and the same # symbol is used in Powershell, Ruby, Python, and other languages.
There are two ways we can comment out the text or code in Powershell.
# Hash Symbol for single-line comments in Powershell.
Example 1
# This powershell command get's service status of AdobeARMservice Get-Service -Name AdobeARMservice
Multiline comment in PowerShell.
# Single line comment in Powershell <# -------------------------------------- Your Multi-line comment in PowerShell -------------------------------------- #>
For multiline commenting in Powershell, we have to use <# your text or code#>
Examples 2
<# Script Author Raj, Last modified 4/24/2020 This powershell scripts get the C drive space on remote multiple remote computer. Please store the servers list here c:\temp\Allservers.txt #> $allservers =get-content -path "c:\temp\Allservers.txt" foreach ($oneserver in $allservers) { $disk = Get-WmiObject Win32_LogicalDisk -ComputerName $oneserver -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace $diskinfo = Get-PSDrive C | Select-Object @{ E={$_.Used/1GB}; L='Used' }, @{ E={$_.Free/1GB}; L='Free' } } $disk.Size $disk.FreeSpace
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply