Yesterday’s post, “How To Get The PowerShell Version”, discussed how to get the PowerShell version that you are running under.

In this post, we will look at a simpler challenge - how to get the edition.

As a reminder, there are two editions of PowerShell:

  1. PowerShell For Windows (version 5 and below)
  2. PowerShell Core (Version 6 and above, 7 being the current)

One way would be to ride on what we learned yesterday.

We can use this invocation:

$PSVersionTable.PSVersion

From this, we can extract the property MajorVersion.

If it is 5, then that is PowerShell for Windows.

If it is larger than 5, then that is cross-platform PowerShell Core.

There is another, simpler way to obtain this information..

We can use the following invocation:

$PSVersionTable.PSEdition

If we run it under PowerShell for Windows, we get the following result:

PowerShellWindowsEdition

It returns a string value, Desktop

We can also run it under PowerShell Core on Windows.

PowerShellCoreWindowsEdition

It returns a string value, Core

On macOS, which can run PowerShell Core, it returns the same:

PowerShellmacOSEdition

TLDR

You can obtain the PowerShell edition from the $PSVersionTable.PSEdition invocation.

Happy hacking!