Greater than and less than comparison

PowerShell has two operators to compare two values to determine whether they are greater than (–gt) or less than (-lt) each other. This is not just limited to numbers, but also has the ability to compare dates and times as well. These are helpful in instances where you need to compare file sizes or modification dates on files.

A script that shows how to use the "less than" comparison operator would look like this:

$number1 = 10
$number2 = 20
If ($number1 –lt $number2) { Write-Host "Value $number1 is less than $number2" }

The output of this command is shown in the following screenshot:

Greater than and less than comparison

In the preceding example, ...

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.