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.
Powershell supplies a number of help files on the various operators. We recommend that you read them in conjunction with this chapter. The help files contain numerous examples that will aid your understanding. The following help files are available:
- about_Operators
- about_Arithmetic_Operators
- about_Assignment_Operators
- about_Comparison_Operators
- about_Logical_Operators
- about_Operator_Precedence
- about_Type_Operators
All of these operators have a common syntactical form. Practically all PowerShell 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.
Comparison operators are designed to take two pieces of data and compare them. They always return either True or False, known as Boolean values, based on whether or not the comparison was true.