Thursday, September 12, 2013

PowerShell Techniques : Commenting Scripts, it’s always helpful.



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:

  1. If you are writing a long script, you will know what you are doing.
  2. If you want to share the script with one else,, they can also understand the script by reading comments.
  3. We can define a separate section for variable,function using comments.
  4. 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,

12-09-2013 23-09-27

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.

12-09-2013 23-16-52

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.


Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

1 comment:

  1. I am sure that you should read if you want to be a pert-time student. Here you can read some useful advices