Author Posts

February 2, 2017 at 2:09 pm

Hello,

This question applies to all programming not just Power shell. Besides reducing the number of lines in a code if you're entering the same code more than once, is there any other benefits to using functions?

For example, does it make the program any faster? Any other advantages / Disadvantages?

Thank you,

Tony

February 2, 2017 at 2:18 pm

A couple that immediately come to mind.

Re-usability. A function can be like a tool you've built and tested. You copy it out of one script and put it in another.

Readability. Sometimes you need a large block of code to perform a seemingly simple action. By creating a function with meaningful name, you can make your code easier to follow.

February 2, 2017 at 5:41 pm

I'd also add that if your code is created as Advanced functions it can be packaged as a module