Using an interactive shell

Windows PowerShell can be used either interactively or as a script automation. Before we take a look at script automations, let's explore the use of an interactive shell.

We can do arithmetic operations in Windows PowerShell as follows:

2 + 2

This will return 4. Consider the following operation:

2 + 2 * 3

This will return 8.

Windows PowerShell does left-to-right arithmetic operations according to the precedence rules. In the preceding expressions, PowerShell performed the operation as 2 * 3 + 2. We need to use parenthesis, as with (2 + 2) * 3, which return the result as 12. Here, (2 + 2) is known as grouping.

Using Windows PowerShell, we can do much more, such as system unit calculations, hexadecimal conversions, and so ...

Get PowerShell: Automating Administrative Tasks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.