Learning PowerShell — Let’s Do It Together — Part 3

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables?view=powershell-7, https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7

So far we have discussed the cmdlets. Now we will take a look onto variables and then we will discuss different operators which can be performed.


Variables are storage spaces which when defined the OS allocates them space. We use variables to store our data. In PowerShell defining variable is different as different programming languages as well as scripting languages define variables using their own conventions.

Variables in PowerShell start with a Dollar Sign ($). Examples are as above.





Let’s work with different operators. At first we will take a look onto assignment operator (=). This operator is used to define values into variables.

We defined a variable and then added an integer. We can output the variable values by directly calling the variables. Let’s add characters into a variable. We do this similar to other languages i.e. by putting the characters in single quotes or double quotes.

Let’s add float values into the variable.

Let’s add strings into the variable.


Now we have a good understanding of the variables. Now let’s take a look onto different operators available in PowerShell.

There are common arithmetic operators which are supported by PowerShell. Take a look onto the above screenshot!

There are common assignment operators which are supported by PowerShell. Take a look onto the above screenshot.

Comparison operators definitions are different from the ones in other programming languages although their working is same as of others.

-eq → Equals To
-ne → Not Euals To
-gt → Greater Than
-lt → Less Than
-ge → Greater Than or Equals To
-le → Less Than or Equals To

Example is as above!

These operators are used to find and replace patterns in text. These include the following. These operators use regular expressions.

-match → To match a particular value
-notmatch → To check if there is no match of the value
-replace → To replace a particular value

Example is as above!

-match → Matches if a string exists in the data.
-notmatch → Checks if a particular string does not exists.
-replace → Replaces a particular string with the string provided.

These operators determine whether a test value appears in a reference set or not.

Example is as above!

-in → Checks if a particular value exists in the array or in set of values.
-notin → Opposite of -in
-notcontains → Checks if a value exists in the set or not!

These operators are used to check for the conditions and also are used to write complex statements with ease. There are a number of logical operators in PowerShell.

All details regarding PowerShell operators can be found on the above link!