PowerShell Arithmetic Operators

In this tutorial we will see about PowerShell Arithmetic Operators and how PowerShell is dealing with them.


Arithmetic operators are used to perform numeric calculations. As well as numeric calculations, the addition operator may also be used with strings, arrays, and hashtables. Multiplication operator may also be used with strings and arrays.

Below is the list of PowerShell arithmetic operators.

OperatorDescriptionExample
+Adds numeric values4 + 6
concatenates a string, arrays, and hash tables“CS” + “Tutorials”
Subtracts numeric values4 – 2
Makes a number negative-98
*Multiple numeric values4 * 2
copy string, arrays to the specified number of times“!” * 4
/Divides numeric values4 / 2
%Gives remainder after division7 % 3
For live demo, watch below video. I have demonstrated the use of PowerShell arithmetic operators by  creating calculator. Along with operators, Switch statement and While loop also used.


 

Comments

Popular Posts

How to Import and Export Delimited Files, like CSV, in PowerShell

How to generate a GUID in PowerShell