I hope you are enjoying my Powershell Techniques series of web post. I always mention in most of my blog posts that, learning or memorizing what cmdlets do is really easy , but it is bit difficult to find techniques.
In my opinion these tips and trick or we can say techniques are universal, these are more then a logic and can apply anywhere and in any scripting language.
When you write Powershell script, it is always handy to add comments on them, as we know, in Powershell we use hash(#) character to add comments.
Why it is important to add comments?
In my point of view it is very important, because:
- If you are writing a long script, you will know what you are doing.
- If you want to share the script with one else,, they can also understand the script by reading comments.
- We can define a separate section for variable,function using comments.
- if we are using lots of foreach,if, loops, it is easy to identify ending of each loops.
In my scripts I use comments as separator. You can see that, I define a separate space for the Variable, Modules, Functions, So when next time, if i want to add of troubleshoot any functions, at that time i know where to look for them,
It is always good to add comments above your code, so that you know what that code is doing.,This helps you and helps other to understand your scripts.
If you are using multiple if/else or other loop and statements, then you can also use #comments in the end of } braces, you that you know which logic is applying on it.
That’s all for now.