0

I am using the .NET PowerShell host. I have version 5 and 7 installed of PowerShell. When running:

$PSVersionTable.PSVersion

  • it returns:

Major Minor Build Revision


5 1 18362 1110

How do I make it run version 7 of PowerShell?

2
  • 3
    "I am using the .NET PowerShell host", I assume this means compiling against .NET Framework? PowerShell 7 runs on .NET Core >3.1, so you won't be able to use it from a .NET Framework host. Commented Nov 6, 2020 at 12:45
  • Yes, correct. Makes sense. Thanks. Commented Nov 6, 2020 at 15:35

3 Answers 3

3

From Microsoft's documentation, you should be able to load a previous version of PowerShell.

Separate installation path and executable name

PowerShell 7 installs to a new directory, enabling side-by-side execution with Windows PowerShell 5.1.

Install locations by version:
Windows PowerShell 5.1: $env:WINDIR\System32\WindowsPowerShell\v1.0
PowerShell Core 6.x: $env:ProgramFiles\PowerShell\6
PowerShell 7: $env:ProgramFiles\PowerShell\7

The new location is added to your PATH allowing you to run both Windows PowerShell 5.1 and PowerShell 7. If you're migrating from PowerShell Core 6.x to PowerShell 7, PowerShell 6 is removed and the PATH replaced.

In Windows PowerShell, the PowerShell executable is named powershell.exe. In version 6 and above, the executable is named pwsh.exe. The new name makes it easy to support side-by-side execution of both versions.

Have a read of the webpage, using the link provided.

https://learn.microsoft.com/en-us/powershell/scripting/install/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7

Sign up to request clarification or add additional context in comments.

Comments

1

Powershell (Core) 7 is a different executable: pwsh.exe

powershell => Windows PowerShell (latest: v5.1)
pwsh => PowerShell Core (latest: v7)

Comments

1

From a console just do

where powershell.exe

-and-

where pwsh.exe

you should obtain:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-and-

C:\APL\Microsoft\PowerShell64\pwsh.exe

then you can call the .exe(s) direcly...
to bypass any issues with .cmd(s)/.bat(s)/.lnk(s)/alias/hijackers/etc. etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.