PowerShell Genie

PowerShell 5.1 and PowerShell 7

Windows PowerShell 5.1 is built on the .NET Framework, ships in the box on Windows, and is in maintenance mode. Its executable is powershell.exe. PowerShell 7 is built on .NET, runs on Windows, Linux and macOS, and is where all new work happens. Its executable is pwsh (pwsh.exe on Windows).

Lesson 3 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Overview

They install side by side and do not interfere with each other. That is deliberate: plenty of older scripts and a few Windows-only modules still expect 5.1, so replacing it would break things.

The practical differences that will actually catch you out are the default text encoding (5.1 writes UTF-16 or ANSI depending on the cmdlet, 7 writes UTF-8 without a BOM), the availability of newer operators and ForEach-Object -Parallel in 7 only, and a handful of Windows-specific modules that load in 5.1 but not in 7. Whenever a script behaves differently on two machines, check which edition you are in first.

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 | Select-Object PSEdition, PSVersion
  1. Stage 1$PSVersionTablePositional values or no named parameters
  2. Stage 2Select-ObjectPositional values or no named parameters

    What happens

    $PSVersionTable is an automatic variable that PowerShell fills in at startup. PSEdition reads Desktop for Windows PowerShell 5.1 and Core for PowerShell 6 and later. PSVersion gives the full version number. This is the fastest way to establish which shell you are actually sitting in, which matters more often than people expect.

    Worth remembering

    • powershell.exe is 5.1, pwsh.exe is 7. They coexist.
    • PSEdition says Desktop for 5.1 and Core for 7.
    • Default file encoding differs, which breaks scripts that write text.
    • Some Windows-only modules are still 5.1 only.

    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. You must run a script on a server that has no .NET Core installed and cannot reach the internet. Which edition do you target?

    Answer: Windows PowerShell 5.1 — it ships with Windows and needs nothing installed. PowerShell 7 would require an offline install first.

    Q2. True or false: $PSVersionTable.PSEdition returns "Desktop" on PowerShell 7.

    Answer: False — on PowerShell 7 it returns "Core"; "Desktop" is the Windows PowerShell 5.1 answer.

    Q3. A colleague’s script uses Get-WmiObject and fails on your machine with "not recognized". You run $PSVersionTable.PSVersion and see 7.4. What happened?

    Answer: The WMI cmdlets were removed in PowerShell 7 — run the script under Windows PowerShell 5.1, or rewrite it with the CIM cmdlets (Get-CimInstance).

    Primary documentation

    Differences between Windows PowerShell 5.1 and PowerShell 7

    Try it

    Illustrative output · values vary by environment

    1PS> $PSVersionTable | Select-Object PSEdition, PSVersion

    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.

      Reports which edition and version you are running. Check this before debugging anything version-sensitive.

      Show reference output

      Illustrative output · values vary by environment

      PSEdition  PSVersion
      ---------  ---------
      Core       7.5.2

      Practise this

      Distinguish Core from Desktop

      Display the PSEdition value.

      Review the lesson

      Keep going

      Next: Update PowerShell on Windows without confusing editions
      Genie guidePowerShell 5.1 and PowerShell 7

      Windows PowerShell 5.1 is built on the .NET Framework, ships in the box on Windows, and is in maintenance mode. Its executable is powershell.exe. PowerShell 7 is built on .NET, runs on Windows, Linux and macOS, and is where all new work happens. Its executable is pwsh (pwsh.exe on Windows).