Comments

I'd like to introduce comments right at the beginning. As you may know (from other scripting or coding languages), comments are necessary to describe and explain your code. Developers often argue that code is self-explanatory, but that is a lie. You will quickly learn that, even when working with your own scripts, it is always good to have some comments on the side. You can use either line comments or comment blocks in PowerShell, which make use of the key character (#), and look as follows:

# this is a comment line
## this as well

<#
this is a comment block
#>

<# this as well
this as well
this as well
#>

As we are starting with the basics, you should know that there are some best practices for writing code. We will provide many of them throughout this book, but the most important one is to always provide comments with your code, to help the reader, other coders, or even yourself, if you need to reuse or debug your code. If you need to write multiline comments, you can use comment blocks. For most of the other scenarios, line comments fulfill the job. Later on, you will see other commenting techniques, and how they can be valuable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.233.41