TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Logical Operators

PowerShell Logical Operators with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

Logical Operators

The logical operators are used in PowerShell to connect expressions or statements together to form a single expression. Those expressions which contain these operators usually results in the Boolean values True or False. These operators allow us to use a single expression to test for multiple conditions.

PowerShell supports the following logical operators:

PowerShell Logical Operators
  1. -and (Logical AND)
  2. -or (Logical OR)
  3. -xor (Logical XOR)
  4. -not (Logical NOT)
  5. ! (Same as Logical NOT)

-and (Logical AND)

The AND operator is the logical operator, which returns the Boolean value TRUE if both the conditions are correct in an expression.

Example: The following example describes how to use the logical AND operator:

$a=10
$b=20
($a -lt $b) -and ($a -eq 10) 

The last command in this example displays the Boolean Value TRUE because both the conditions are correct.

-or (Logical OR)

The OR operator is the logical operator, which returns the Boolean value TRUE if at least one of the conditions is correct in an expression.

Example: The following example describes how to use the logical OR operator:

$a=5
$b=30
($a -lt $b) -or ($a -eq 11) 

The last command in this example displays the Boolean Value TRUE because the first condition in this statement is correct.

-xor (Logical XOR)

The XOR operator is the logical operator, which returns the Boolean value TRUE if only one condition is correct in expression. When more than one statement is correct in expression, this operator returns the FALSE.

Example: The following example describes how to use the logical XOR operator:

$a=5
$b=30
($a -lt $b) -xor ($a -eq 11) -xor ( $b -eq 30)

The last command in this example displays the Boolean Value FALSE because, in this expression, the two conditions are correct.

-not (Logical NOT)

The NOT operator is the logical operator that produces the opposite result of an expression. If an expression gives TRUE value, then this operator will return FALSE and vice versa.

Example: The following example describes how to use the logical NOT operator:

$a=5
$b=30
-not ( $b -eq 30)

The last command in this example displays the Boolean Value FALSE because, in an expression, the condition is correct, but this operator turns to the opposite.

! (Same as Logical NOT)

This operator is same as the logical NOT operator that produces the opposite result of an expression.

Example: The following example describes how to use this operator:

$a=5
$b=30
! ($a -gt $b)

The last command in this example displays the Boolean Value TRUE because, in an expression, the condition is not correct, but this operator turns the result to the opposite.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf