PowerShell Basics Level: Beginner Chapter 2: Your First PowerShell Commands

PowerShell versions

There are two families: Windows PowerShell, which ships with Windows, and PowerShell, the cross platform edition. Knowing which one you run avoids surprises.

Lesson 2 of 5 in Chapter 2: Your First PowerShell Commands. Previous step in this path: What is PowerShell. 3 learning objectives, 6 examples, and a knowledge check.

Start: what you will learn

There are two families: Windows PowerShell, which ships with Windows, and PowerShell, the cross platform edition. Knowing which one you run avoids surprises.

Learning objectives

  • Tell Windows PowerShell apart from PowerShell
  • Check the version on your own computer
  • Explain why a command can differ between versions

Concept in simple words

What it is: A PowerShell version is the edition and release number of the PowerShell you are running, and there are two main families, Windows PowerShell 5.1, which ships with Windows, and PowerShell 7 and later, which runs on Windows, macOS, and Linux. The word edition means which family you are in. The word version means which release inside that family, such as 5.1 or 7.

Why it works

Why it exists: PowerShell started as a Windows only tool. Later, Microsoft rebuilt it on a newer, cross platform base, so it could also run on macOS and Linux. The old Windows only family was kept, because many Windows computers and scripts still depend on it. The result is two families that share most of the language, but are not identical.

What problem it solves to know this: If you follow a guide and a command does not work, you need a first question that is fast and reliable. That question is: which edition and version am I running? Many so called broken commands are not broken at all. They were simply written for the other family, or for a newer release than the one you have.

Why it works this way: The two families were built at different times, so they do not include exactly the same commands and modules, which are packages of commands. A command that exists in one edition can be missing or different in the other, and that is why checking the version first saves confusion later. The edition is also tied to the underlying runtime, which is the engine the language runs on, so some building blocks are available in one edition and not in the other.

Think of it like this

Think of it like this: It is like two editions of the same handbook. Most of the language is the same, but some pages were added, some were rewritten, and a few only exist in one edition. If an example does not work, the first question is simple, which edition are you holding.

A second analogy that helps: Think of two phones from the same maker, an older model and a newer model. Most apps work on both, but a new feature may need the newer model, and an old accessory may fit only the older one. You would not say the phone is broken before you checked which model you hold. Checking your PowerShell edition is the same kind of check.

How it works, step by step

How it works, step by step: First, open PowerShell and type $PSVersionTable, then press Enter. This is a built in variable, which is a named value PowerShell keeps for you, and it holds facts about your current session. Then look at the PSVersion row for the version number, and the PSEdition row for the edition name.

How to read the table, row by row: The table has two columns, Name and Value. Name is the label, such as PSVersion or PSEdition. Value is the fact for that label. PSVersion tells you the release number. PSEdition tells you the family, Desktop for Windows PowerShell 5.1, or Core for PowerShell 7 and later. Other rows give extra facts, such as which versions are compatible, and they can differ between editions, so do not be surprised if your table has more or fewer rows than an example.

How it works, step by step, continued: Next, compare what you see with the example you are following. If the example needs PowerShell 7 and you are on 5.1, or the other way round, do not force it. Find the version of the example that matches your edition, or ask which edition it was written for. Forcing a command from the other edition usually wastes time, and it can lead you to change settings you did not need to change.

Let us walk through an example: In $PSVersionTable.PSVersion, the dollar sign marks a variable, PSVersionTable is the name of the variable, and .PSVersion reads one property from it, which is one fact stored inside it. The output shows the version as separate numbers, such as Major and Minor, so you can see the release at a glance. Major is the big release number, such as 5 or 7. Minor is the smaller release number after it, such as 1 in 5.1.

Walkthrough, what changes if you change one part: If you type $PSVersionTable on its own, you see the whole table. If you type $PSVersionTable.PSVersion, you see only the version fact. If you type $PSVersionTable.PSEdition, you see only the edition word, Desktop or Core. If you type $PSVersionTable.PSVersion.Major, you see only the big number, 5 or 7, which is enough for a quick check. The variable did not change. You only asked for a smaller part of it.

Let us walk through a second example: In $PSEdition, the dollar sign again marks a variable, and PSEdition is its name. This variable holds only the edition word, so it is a shortcut for $PSVersionTable.PSEdition. If it shows Desktop, you are in Windows PowerShell. If it shows Core, you are in PowerShell 7 or later. Use it when you only need the edition, and use the full table when you also need the version number.

How to tell the two programs apart before you even type: On Windows, Windows PowerShell is usually started with the program name powershell, and PowerShell 7 is usually started with the program name pwsh. The window title and the prompt can also differ, but do not rely on looks alone. The table is the reliable check, because a window can be renamed or themed, while $PSVersionTable always reports the session you are actually in.

When to use it

When to use it, and when not to: Always check your version before you follow a guide, copy an example, or report that a command does not work. Do not assume a guide uses your edition, and do not switch editions in the middle of a task without checking whether your commands still work there. Switching is not wrong, but switching without checking is how a working task turns into a confusing one.

Common edge cases to expect: First, one computer can have both editions installed side by side. Opening the wrong one by accident is common, and the fix is simply to check the table and open the other one. Second, the version table layout can differ between editions, for example the version fact may show Build and Revision in one edition and Patch in another. Read the labels Major and Minor first, and do not panic about the extra numbers. Third, a command that is Windows only, such as a service command, may not be available on macOS or Linux, even in PowerShell 7, because it depends on Windows itself.

A safe habit for asking for help: When you ask someone why a command failed, always include two facts: the full command you ran, and the result of $PSVersionTable. Those two facts let the other person spot an edition mismatch in seconds, instead of guessing through many messages.

Worked examples

Read each example in order. Each one explains its parts, then shows what to look for in the output.

Syntax

Syntax
$PSVersionTable

Example 1

Shows version facts about the PowerShell you are running right now.

Example 1
$PSVersionTable

Illustrative output: PSVersion 5.1 PSEdition Desktop

Example 2

Shows only the version number, using dot notation to read one property.

Example 2
$PSVersionTable.PSVersion

Illustrative output: Major Minor Build ----- ----- ----- 5 1 19041

Example 3

This reads one property, PSEdition, from the $PSVersionTable variable. PSEdition names the edition, for example Desktop for Windows PowerShell 5.1 or Core for PowerShell 7 and later. Use it together with the version number when you describe a problem to someone else.

Example 3
$PSVersionTable.PSEdition

Illustrative output: Desktop

Example 4

Reads only the Major number from the version fact. Look for a single number: 5 points to Windows PowerShell 5.1, and 7 points to PowerShell 7 or later. This is the fastest yes or no check when you only need to know which family you are in.

Example 4
$PSVersionTable.PSVersion.Major

Illustrative output: 5

Example 5

A shortcut variable that holds only the edition word. Compare it with the PSEdition row in the full table: both should show the same word, Desktop or Core. If they differ, trust the table and check that you are in the session you think you are in.

Example 5
$PSEdition

Illustrative output: Desktop

Example 6

Reads only the Minor number, the smaller release number after the Major number. Together, Major and Minor give you the familiar form, such as 5.1, without the extra build numbers. Use it when a guide says it needs a certain minor release and you want to check that one number.

Example 6
$PSVersionTable.PSVersion.Minor

Illustrative output: 1

Nothing on this page executes PowerShell code. The outputs above are illustrative only.

Common mistakes and troubleshooting

Read these before you try the examples, so you can spot the same problems in your own work.

  • Assuming every guide uses the same edition you have. Check first.
  • Copying a version 7 example into Windows PowerShell 5.1 without checking whether the module exists there.
  • Reporting that a command is broken without first checking $PSVersionTable, when the real cause is simply that the example was written for the other edition.
  • Reading only the first number and ignoring the edition. A version number alone does not tell you the family, so always read PSVersion together with PSEdition.
  • Assuming that having both editions installed means they share settings or history. They are separate programs, so open the edition you mean to use, and check the table in that window.
  • Judging the table by its row count. Different editions show different extra rows, so compare the PSVersion and PSEdition rows, not the total number of rows.

Knowledge check

Knowledge check

Which edition ships built into Windows as version 5.1?

Pick one answer. Feedback appears right away, and you can try again.

Remember this and next step

Remember this: Windows PowerShell 5.1 ships with Windows, PowerShell 7 and later is cross platform, and $PSVersionTable tells you which one you are running. Check it first, before you blame the command, the guide, or yourself.

Next step: Work environments: ISE, console, and VS Code