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

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:

In the preceding example, you set the $number1 variable to 10 and the $number2 variable to 20. You then use the "less than" (–lt) operator to determine whether the $number1 variable is less than $number2. Since this a true statement, the console outputs the message Value $number1 is less than $number2.

A script that shows how to use the "greater than" comparison operator would...