Getting Started with the PowerShell Console

I. Introduction

In this chapter, we'll be taking our first steps with the PowerShell console - or rather, PowerShell consoles, as there are two separate consoles if your machine is equipped with Windows PowerShell and PowerShell. We'll be looking at the various installation directories, as well as how the PowerShell console works.

II. Where to install PowerShell

You should be aware that Windows PowerShell and PowerShell are not installed in the same directory. Each executable also has a different name. This is what we'll be looking at in this part of the chapter.

A. Where is Windows PowerShell installed?

On a machine on which a 64-bit version of Windows is installed, there are two versions of Windows PowerShell installed : a 32-bit version and a 64-bit version. If a 32-bit version of Windows is used, there is only one console.

The Windows PowerShell console is installed in the Windows directory at this location :

%SystemRoot%system32WindowsPowerShellv1.0
# Soit :
C:WindowsSystem32WindowsPowerShellv1.0

Inside this directory, we find a set of files, including"powershell.exe" corresponding to the Windows PowerShell console, and"powershell_ise.exe" corresponding to the Windows PowerShell ISE code editor.

Windows PowerShell installation path

If you're on a machine with a 64-bit version of Windows, you'll also find the 32-bit versions of the PowerShell console and PowerShell ISE in this directory:

%SystemRoot%SysWOW64WindowsPowerShellv1.0
# Soit :
C:WindowsSysWOW64WindowsPowerShellv1.0

We can see that the installation directory contains a peculiarity in its path: "v1.0". When we read this, we might think that this value indicates the version of Windows PowerShell installed on the machine. In reality, it doesn't. The value will always be"v1.0", whether you have Windows PowerShell 2.0 or Windows PowerShell 5.1.

At the time, when PowerShell was introduced to Windows, Microsoft probably had the idea of making the folder name evolve according to the PowerShell version, but this idea was abandoned. To find out which version of PowerShell is actually installed on the machine, read the contents of the $PSVersionTable automatic variable mentioned in a previous chapter.

B. Where is PowerShell installed?

If you install PowerShell on your machine, for example, the latest version of PowerShell 7, you should be aware that it will be installed in a different directory. This directory can be customized at the time of installation.

By default, PowerShell will be installed in this directory (although this path may change slightly if a 32-bit version is installed on 64-bit Windows):

C:Program FilesPowerShell7

In this directory we find the PowerShell executable: pwsh.exe, which has a different name from the Windows PowerShell executable (powershell.exe).

PowerShell 7 installation path on Windows

In addition, we can see that the path includes the major version number of this PowerShell version. In this example, we have"7" in the installation path. This value corresponds to the major version in use, even if we still need to call up the $PSVersionTable variable to find out the exact version installed on the local machine.

III. Opening the PowerShell console

Now that we know where the Windows PowerShell and PowerShell consoles are installed, let's learn how to use them. As you may have guessed, to use Windows PowerShell, open"powershell.exe", while to use PowerShell, open"pwsh.exe".

To save time, you can search for PowerShell using the machine's Start menu search box . There's no need to access the installation directories to locate the executable. What's more, if we take the example of a machine running Windows 11, you should be aware that the Windows Terminal application is preinstalled. This application makes itvery easy to use several types of console, including PowerShell, Windows PowerShell, Command Prompt and Azure Cloud Shell, to name but a few.

This application is not preinstalled on Windows Server, although it can be added. This should change with Windows Server 2025, since the Preview version of this future version of Windows Server includes Windows Terminal.

A. How does the PowerShell console work?

Let's take a look at how the PowerShell console works, using the PowerShell 7 console (pwsh.exe) as an example. Both consoles work in the same way. On your machine, open PowerShell (via a search in the Start menu, for example).

Open PowerShell on Windows 11

The PowerShell console will open. On a Windows 11 machine, it opens in Windows Terminal, as this application is defined as the default terminal application in the system settings. This console takes the form ofan interactive shell, i.e. commands can be written and executed.

Note : Windows Terminal offers a wide range of options for customizing its operation, creating specific connection profiles and modifying its graphical appearance. It can open multiple consoles of different types in a single window.

Beyond the PowerShell version, which is specified on the first line, what's important is the prompt. This is the following information:

PS C:Program FilesPowerShell7>

This means that our console is positioned in this directory, at the level of our machine's file system. In other words, this is our current, default working location.

How the PowerShell console works

If we execute the command below, we'll move to the root of the"C:" volume. This will change the prompt value. The Set-Location cmdlet (equivalent to "cd") lets you move from one location to another. This is important, because if we create a file or folder without specifying a destination directory, the current working directory will be used (the one mentioned between "PS" and ">"): in this case, the file would be created at the root of "C:".

PowerShell 7 - Set-Location

From this console, we can execute complete PowerShell commands, as well as PowerShell scripts and programs. As soon as a PowerShell command is executed, it is processed by the computer and the result is returned to the console. What's more, every command executed in the console is recorded in the history (since PowerShell 5.0) thanks to the PSReadLine module natively integrated into Windows.

The easiest way to navigate through this history and access recent commands is to use the up and down arrows. Here's your chance to make the transition to the next part of this chapter.

B. Useful keyboard shortcuts for using the PowerShell console

The PowerShell console is mostly operated via the keyboard, although it is possible to select text with the mouse. As a result, there are a number of keyboard shortcuts you need to know to get to grips with the PowerShell console.

Here are the main key combinations:

Key combinationsAction taken
Directional up arrow and directional down arrow Navigate the history of executed commands
Left directional arrow and right directional arrow Move on a line when entering a command in the PowerShell console
Start" buttonReturn to the beginning of the line
End" buttonGo to end of line
Tabulation" keyUsing PowerShell command autocompletion
Ctrl" +"Space bar" keysObtain a list of possible values (including the list of parameters available for a command)

We'll be putting them into practice as we get to grips with PowerShell.

C. Open the PowerShell console with administrator rights

Finally, we'd like to mention an important point: running the administrator console with administrator rights.

By default, the PowerShell console opens in the context of the user logged on to the Windows machine. So, if the console is opened from an account that is a standard user, then the PowerShell console will not allow you to perform certain actions. For example, you won't be able to modify the system configuration, because you won't have sufficient rights.

In this case, you need to perform an elevation of privileges so that PowerShell can be run with the permission level of an administrator. Either you know the login and password of an administrator account, or your account is already the local administrator of the machine (at the very least).

To open PowerShell (or Windows PowerShell) as an administrator, simply right-click on the application name and click on"Run as administrator".

PowerShell - Run as administrator

You can also run Windows Terminal as an administrator. It has the advantage of being directly present in the context menu that appears when you right-click on the Windows Start menu.

Windows Terminal - Run as administrator

If you open two Windows Terminals, one in the user context and the other as administrator, you may notice a difference: the presence ofa shield icon, which highlights the one being run with high permissions. In addition, the title of the PowerShell console contains the prefix"Administrator:". Here's an example:

Windows Terminal - Administrator icon

IV. Conclusion

There's no secret to getting to grips with the PowerShell console: just manipulate it. Please note that PowerShell commands cannot be executed directly from a "Command Prompt" console. In fact, in the next chapter of this course, we'll be looking at the notion of PowerShell commands, or rather PowerShell cmdlets.