serializer
serializer

Reputation: 1013

Setting Powershell version used in the PowerShell host?

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

$PSVersionTable.PSVersion

Major Minor Build Revision


5 1 18362 1110

How do I make it run version 7 of PowerShell?

Upvotes: 0

Views: 1292

Answers (3)

Shaqil Ismail
Shaqil Ismail

Reputation: 1979

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

Upvotes: 3

ZEE
ZEE

Reputation: 3193

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.

Upvotes: 1

marsze
marsze

Reputation: 17154

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

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

Upvotes: 1

Related Questions