Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Best practices for functions, switches, and loops


When you are scripting, you will find that you frequently need to utilize functions, loops, switches, and methods. Each of these code structures enable you to produce code faster so that you don't have to repeat code within your script. As you work with each of these structures, there are several best practices that you can follow.

Best practices for functions

There are a few recommended steps that can be followed to obtain optimum performance from functions. They are listed as follows:

  • If you need to execute a sequence of code more than once, you should create a function. This will allow you to quickly repeat the same action without significantly increasing the size of the script.

  • If you need to pass information into a function for processing, you should leverage arguments. Arguments will need to be declared in the order by which the function will use them.

  • If you need to pass information back from a function, you should utilize the return command...