Basic function question


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,


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.

Thank you

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