Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Windows PowerShell Scripting

You're reading from   Mastering Windows PowerShell Scripting Master the art of automating and managing your Windows environment using PowerShell

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781782173557
Length 282 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Brenton J.W. Blawat Brenton J.W. Blawat
Author Profile Icon Brenton J.W. Blawat
Brenton J.W. Blawat
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Variables, Arrays, and Hashes FREE CHAPTER 2. Data Parsing and Manipulation 3. Comparison Operators 4. Functions, Switches, and Loops Structures 5. Regular Expressions 6. Error and Exception Handling and Testing Code 7. Session-based Remote Management 8. Managing Files, Folders, and Registry Items 9. File, Folder, and Registry Attributes, ACLs, and Properties 10. Windows Management Instrumentation 11. XML Manipulation 12. Managing Microsoft Systems with PowerShell 13. Automation of the Environment 14. Script Creation Best Practices and Conclusion 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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image