Equal and not equal comparison

The most basic and most used comparison operator is equal to (-eq). This operator is flexible in nature as it can be used for strings, integers, and objects. The -eq operator is used by calling value1 is equal to value2. When the –eq operator evaluates the statement, it will return a Boolean value of either True or False. If the expression evaluates to be True, PowerShell will continue to proceed to execute the code.

A script that shows how to use equal comparison operators would look like this:

$value1 = "PowerShell"
$value2 = "PowerShell"
if ($value1 –eq $value2) { Write-Host "It's Equal!" }

The output of this is shown in the following screenshot:

From the preceding example, you will see that the equal comparison ...

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.