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 ...

Get Mastering Windows PowerShell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.