A scenario you might run into is when you want to check the PowerShell version under which you are running.

This is complicated by the fact that there are two flavours of PowerShell

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

For either, you can examine the $PSVersionTable variable, particularly the PSVersion property.

Like so:

$PSVersionTable.PSVersion

In PowerShell For Windows, you will see something like this:

PowershellWindows

In PowerShell Core, running in Windows, you will see something like this:

PowerShellCoreWindows

In macOS, you will see something like this (if you have installed PowerShell):

PowershellmacOS

TLDR

You can get the PowerShell version by querying the $PSVersionTable.PSVersion variable.

Happy hacking!