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 comparison operators


PowerShell offers many different comparison operators for use within your scripts. It is easy to start building overly complex scripts by overusing comparison operators or by evaluating items that you may not have to use in PowerShell functioning. Refer to the following guidelines to stick to when you are developing your scripts. These will help you avoid overuse of comparison operators:

  • Assume the script is designed to proceed: When you assume your script is designed to proceed to the next step, you can reduce the number of comparison operators you use. If you expect a value to be True, only make a statement to catch whether the statement is False. Don't check to see whether the statement is True, as PowerShell is designed to sequentially proceed anyway to the next step.

  • Avoid double negative statements: When you are developing your code, avoid the use of double negative statements. Avoid checking to see whether a value does not equal False. What...