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?

serializer
  • 1,003
  • 2
  • 13
  • 27

3 Answers3

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

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
1

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

powershell => Windows PowerShell (latest: v5.1)
pwsh => PowerShell Core (latest: v7)
marsze
  • 15,079
  • 5
  • 45
  • 61
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.

ZEE
  • 2,931
  • 5
  • 35
  • 47