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

And / OR comparison operators


The –and and –or comparison operators are used to evaluate multiple expressions present within a single line of code. These are used to see whether two or more expressions evaluate to be True. The –and comparison operator mandates that both evaluations must evaluate to be True to proceed in the statement. This means that expression1 and expression2 must be True to continue. The –or comparison operator only requires one of the two expressions to be True. This means that expression1 or expression2 can be True to continue. As you are learning PowerShell, you will want to use caution while using the -and and -or comparison operators as they can quickly complicate the logic of your scripts.

A script that shows how to use –and and -or comparison operators would look like this:

$myvar = $True
$myothervar = $False
If ($myvar –eq $True –AND $myothervar –eq $False) { Write-Host "Both statements evaluate to be True" }
If ($myvar –eq $True –OR $myothervar –eq $True) { Write...