- PowerShell - Discussion
- PowerShell - Useful Resources
- PowerShell - Quick Guide
- PowerShell - Alias
- PowerShell - Brackets
- PowerShell - Backtick
- PowerShell - Regex
- PowerShell - Hashtables
- PowerShell - Array
- PowerShell - Conditions
- PowerShell - Looping
- PowerShell - Operators
- PowerShell - Special Variables
- PowerShell - Scripting
- PowerShell - Advanced Cmdlets
- PowerShell - Files I/O
- PowerShell - Dates and Timers
- PowerShell - Files and Folders
- PowerShell - Cmdlets
- PowerShell - Environment Setup
- PowerShell - Overview
- PowerShell - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Powershell - Operators
PowerShell provides a rich set of operators to manipulate variables. We can spanide all the PowerShell operators into the following groups −
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Redirectional Operators
Spilt and Join Operators
Type Operators
Unary Operators
The Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table psts the arithmetic operators −
Assume integer variable A holds 10 and variable B holds 20, then −
Operator | Description | Example |
---|---|---|
+ (Addition) | Adds values on either side of the operator. | A + B will give 30 |
- (Subtraction) | Subtracts right-hand operand from left-hand operand. | A - B will give -10 |
* (Multippcation) | Multippes values on either side of the operator. | A * B will give 200 |
/ (Division) | Divides left-hand operand by right-hand operand. | B / A will give 2 |
% (Modulus) | Divides left-hand operand by right-hand operand and returns remainder. | B % A will give 0 |
The Comparison Operators
Following are the assignment operators supported by PowerShell language −
Assume integer variable A holds 10 and variable B holds 20, then −
Operator | Description | Example |
---|---|---|
eq (equals) | Compares two values to be equal or not. | A -eq B will give false |
ne (not equals) | Compares two values to be not equal. | A -ne B will give true |
gt (greater than) | Compares first value to be greater than second one. | B -gt A will give true |
ge (greater than or equals to) | Compares first value to be greater than or equals to second one. | B -ge A will give true |
lt (less than) | Compares first value to be less than second one. | B -lt A will give false |
le (less than or equals to) | Compares first value to be less than or equals to second one. | B -le A will give false |
The Assignment Operators
Following are the assignment operators supported by PowerShell language −
Operator | Description | Example |
---|---|---|
= | Simple assignment operator. Assigns values from right side operands to left side operand. | C = A + B will assign value of A + B into C |
+= | Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand. | C += A is equivalent to C = C + A |
-= | Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand. | C -= A is equivalent to C = C - A |
The Logical Operators
The following table psts the logical operators −
Assume Boolean variables A holds true and variable B holds false, then −
Operator | Description | Example |
---|---|---|
AND (logical and) | Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. | (A -AND B) is false |
OR (logical or) | Called Logical OR Operator. If any of the two operands are non-zero, then the condition becomes true. | (A -OR B) is true |
NOT (logical not) | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | -NOT(A -AND B) is true |
Miscellaneous Operators
Following are various important operators supported by PowerShell language −
Operator | Description | Example |
---|---|---|
> (Redirectional Opeator) | Redirectional operator. Assigns output to be printed into the redirected file/output device. | dir > test.log will print the directory psting in test.log file |