Chapter 6. Operators

 

This chapter covers

  • Logical and comparison operators
  • Bitwise operators
  • Arithmetic operators
  • Type operators
  • Other special operators

In any computer language, operators provide a means of comparing and manipulating pieces of data. PowerShell’s no exception, offering a wide variety of operators for different tasks.

All of these operators have a common syntactical form. Practically all Power-Shell operators start with a dash or a hyphen, followed by the operator name. You’ll see plenty of examples of this in the following sections and throughout the rest of the book. If you have prior experience with other scripting or programming languages, PowerShell’s operators can seem confusing or odd at first, but you’ll get used to them as you work with them.

6.1. Logical and comparison operators

Comparison operators are designed to take two pieces of data and compare them. They always return either True or False, based on whether or not the comparison was true.

Note

PowerShell has built-in variables ($True and $False) that represent the Boolean values True and False.

Table 6.1 shows the primary comparison operators in PowerShell. In the middle column, we’ve included the more common equivalent from other languages to allow you to match up operators with whatever prior experience you may have.

6.2. Arithmetic operators

 
 
 

6.3. Other operators

 

6.4. Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest