Understanding and using Operators in PowerShell

Introduction to Powershell :

Windows Powershell is a task-based command-line shell and scripting language designed especially for system administration.

Built on the.NET Framework, Windows Powershell helps IT professionals to control and automate the administration of the Windows operating system and applications that run on windows.

Operators in Powershell :

Operator are those which allows us to perform some types of operations between two or more variable.

An operator is a language element that you can use in a command or expression.

Types of Operators in Powershell :

PowerShell supports several types of operators to help you manipulate values.

  1. Arithmetic Operators:

The arithmetic operators are used in a PowerShell to perform the calculation of the numeric values. By using the arithmetic operators, we can addition (+), subtraction (-), multiplication (*), or dividsion(/) the values. These operators also include the modulus (%) operator to calculate the remainder of the division operation.

In PowerShell, the addition and multiplication operator may also be used with the strings, hash tables, and arrays. The (*) operator returns more than one copy of the input, and (+) operator concatenates the input.

For example : Addition of two Strings:

2. Assignment Operators:

The assignment operators are used in the PowerShell to assign one or more values and change or append the values to the variable. These operator can perform the numeric operation before assigning the values to the variables. The most commonly used operator is an assignment operator (=), which assigns the values to the variable.

For example: Use *Assignment Operator to append the string to the variable:

3.Logical Operators:

The logical operators are used in PowerShell to connect expression or statements together to form a single expression. Those expressions which contain these operators usually results in the Boolean value True or False. These operators allow us to use a single expression to test for multiple conditions.

For example: the following example describes how to use Logical AND(-and) Operator.

4. Comparison Operators:

The comparison operators are used in PowerShell to compare the values. By default, all comparison operators are case-sensitive. These operator helps us to find, test, compare, modify, and replace the data and information.

For example: The following example describes using of -eq (equal) operator:

Pursuing MCA from ADYPU