PowerShell Genie

Check your PowerShell version and edition

$PSVersionTable is an automatic variable — PowerShell fills it in for you, no assignment needed. It holds an object describing the running engine: its version, its edition, and the platform it runs on.

Lesson 4 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Meet the pipe

The | character is the pipe. It takes the objects coming out of the command on its left and feeds them as input to the command on its right — read it as "then". $PSVersionTable | Format-List PSVersion, PSEdition, OS, Platform means: take the version object, then show it as a list of just those four properties. Format-List only changes how the properties are displayed; the object itself is untouched.

Inspect this example’s structure

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

$PSVersionTable | Format-List PSVersion, PSEdition, OS, Platform
  1. Stage 1$PSVersionTablePositional values or no named parameters
  2. Stage 2Format-ListPositional values or no named parameters

    Inspect a sample

    1PS> $PSVersionTable | Format-List PSVersion, PSEdition, OS, Platform

    Example reader

    Inspect this page's example

    Fictional browser data when supported

    Run supported commands against the practice data, or inspect the example without executing it.

    Ready to inspect.

      Show reference output
      1 PSVersion : 7.5.2
      2 PSEdition : Core
      3 OS : Microsoft Windows 11 Pro
      4 Platform : Win32NT

      Read the engine version

      PSVersion is the engine version for the current session. PSEdition distinguishes Desktop from Core. Windows PowerShell 5.1 reports Desktop; PowerShell 7 reports Core. OS and Platform are useful in modern PowerShell but are not present in every older session.

      Identify the executable

      Your terminal might run PowerShell 7 (pwsh.exe) while an older script still launches Windows PowerShell 5.1 (powershell.exe). If a script behaves differently than you expect, check which executable is actually running it — the window title usually names it. Changing your terminal settings does not change what an existing scheduled script uses.

      Separate host, engine and module versions

      $Host.Version describes the host implementation and is not the best engine-version test for every hosting application. Get-Module -ListAvailable reports installed module versions; Get-Module reports imported modules. Capture all three dimensions when reproducing a compatibility problem.

      Check both editions

      Launch each intended executable and run the version check inside it. Treat the sample output here as an illustration, not the current release number. Do not infer an engine version from the folder C:\Windows\System32\WindowsPowerShell\v1.0 — despite the name, that is where Windows PowerShell 5.1 lives. The "v1.0" folder name is a leftover from the very first PowerShell release and was never renamed.

      Verify an automation run

      If a script works when you run it by hand but fails when it runs automatically, the automatic run may be using the other PowerShell edition. Add `$PSVersionTable` output at the start of the script so the log shows which edition actually ran it, then compare with what you see in your own terminal.

      Command-line reference

      Show reference output
      1 powershell.exe -NoProfile -Command "$PSVersionTable.PSVersion"
      2 pwsh -NoProfile -Command "$PSVersionTable.PSVersion"

      The code above is a reference for your own terminal. The sample output on this page is a stored fictional example — run the command yourself to see your real version.

      Read the original documentation

      Automatic variables

      Check your understanding

      There is no runnable lab on this page — these run in your own terminal, so predict the answer first, then verify.

      Q1. Before running it: will $PSVersionTable print a single line or a small table?

      Answer: A small table of property names and values (PSVersion, PSEdition, GitCommitId, OS, Platform…). It is an object with properties, not a single string.

      Q2. On PowerShell 7.4, what single value does $PSVersionTable.PSVersion.Major return?

      Answer: 7 — Major is the first part of the version number.

      Q3. From a CMD prompt, where.exe pwsh prints a path but where.exe powershell prints nothing. What does that tell you?

      Answer: PowerShell 7 is installed and on the PATH; Windows PowerShell 5.1 is not on this machine — most likely you are on macOS or Linux, where 5.1 does not exist (it can also be removed from a Windows machine as an optional capability).

      Primary documentation

      about_Automatic_Variables documentation

      Practise this

      Check the installed version

      Display the installed PowerShell version, as a single value.

      Review the lesson

      Keep going

      Next: PowerShell 5.1 and PowerShell 7
      Genie guideCheck your PowerShell version and edition

      $PSVersionTable is an automatic variable — PowerShell fills it in for you, no assignment needed. It holds an object describing the running engine: its version, its edition, and the platform it runs on.