I there a way to force Windows to use PS 7 instead of the old 5?


AlterNate37

Member
Local time
2:56 AM
Posts
30
OS
Windows 11 Pro
Hi,

because of other issues which I'm addressing in another thread I've realized that in my System there is Windows Powershell 5.1, and PowerShell (Core?) 7.5.
When I installed PS7 I've used Chris Titus Utility to make it be the default PS, but it doesn't seem to have worked.
When I evoke PS from Win+X by clicking on "Windows PowerShell (Admin)" (or also the non admin) what opens is the older PS, which has a lighter blue icon.
The new PS is triggered by default only in Terminal.

I was told that trying to forcibly uninstall PS5 can mess up the system. I was told that eventually I can try renaming the exe of PS5 so it can't be triggered anymore, but I wonder if that means that nothing would be triggered or that the system would automatically look for PS7.

I wish to reach two things:
1. that every and each single time where the system or some program needs to run PS, they'll evoke PS7 and not PS5. Or at least that they do whenever possible.
2. that all entries about PS in Win+X are about PS7 and not PS5, or at least that both of them are present (if it's not possible to have only PS7).

How do I achieve that?

I've tried removing PS5 in the environment variables, and pushing up PS7. No idea if I did it properly, but it doesn't seem to be having any effect.

Thanx
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
It's a common mistake for a non-programmer to believe PowerShell 7 replaces PowerShell 5.1.

Both versions are designed to run side by side, and PS7 is not considered a "direct replacement" for PS5. Just like you can have multiple versions of .NET and Visual C++ Runtime on the same Windows. And CMD shell is still around for those scripts which need it.

1. PS5 is executed by calling "powershell.exe", and PS7 is "pwsh.exe". They are deliberately different.
Code:
powershell.exe -f myscript.ps1
pwsh.exe -f myscript.ps1

2. Some library features are only available in PS5, and others only exist in PS7. If a PS script absolutely needs to run on a specific version, it can add "#Requires -Version 7" on the first line. PS5 was originally written specifically to run on Windows, and PS7 was made host-independent and is available for both Windows and Linux.

3. Both of them have separate PS Module paths and profiles.

4. Removing PS5 will break some Windows functionality, as a number of scripts exist which expect powershell.exe to be present.

5. What you can do is change your preference between them in the Terminal app. PS5 is referred to as "Windows PowerShell", and PS7 is known as "PowerShell".

RFjfU.webp

6. You can modify the Win+X shortcut, under folder %LocalAppdata%\Microsoft\Windows\WinX\Group3.

1741652816841.webp
 
Last edited:

My Computer

System One

  • OS
    Windows 7
If a PS script absolutely needs to run on a specific version
Well, that's what I meant too: what if a script does not require to run specifically on PS5?
In a case like that, what can I do to ensure that the system will give preference to PS7?
Environment Variable?
Some tweak in Gpedit or Regedit?
Some PS code with permanent effect?
A utility?

I just want that whenever PS5 isn't absolutely needed it stays put, and PS7 goes on stage instead.


Thanx for the Win+X trick, I'll try it immediately.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
Both versions are designed to run side by side, and PS7 is not considered a "direct replacement" for PS5. Just like you can have multiple versions of .NET and Visual C++ Runtime on the same Windows. And CMD shell is still around for those scripts which need it.

When I say PowerShell below, I mean the newer host, pwsh. Windows PowerShell refers to the "classic" host, powershell.exe.

garlin's quote hints at the actual reason for the separation: Windows PowerShell is based on .NET Framework, and PowerShell is based on .NET (what used to be called .NET Core). The two .NETs have a lot in common, but they are not the same. Modules and such built for Windows PowerShell may indeed work on PowerShell, but one cannot assume that. They have to be tested and then put into PowerShell's modules folder, for example.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
Why do you need to force one version for all running PS instances? There's a brute-force way to do that, but it's discouraged because you can silently break things without realizing it.

Most of the time when you interact with PS, it's whatever version that's launched from the Start Menu, a desktop shortcut or from Terminal. If you're configuring a shortcut or a command to run, you instinctly type "C:\Program Files\PowerShell\7\pwsh.exe" or "pwsh.exe" whenever someone references old powershell.exe.

If you want to run with scissors:
Code:
Windows Registry Editor Version 5.00

[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\powershell.exe]
"Debugger"="C\\Program Files\\PowerShell\\7\\pwsh.exe"

Code:
Windows Registry Editor Version 5.00

[-HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\powershell.exe]
 

My Computer

System One

  • OS
    Windows 7
Why do you need to force one version for all running PS instances?

If you want to run with scissors:
Can you explain what those scissor codes there do exactly? So I can choose if running with scissors or with wolves.

Anyway I don't want to "force" PS7 always.
I want it to be the preferred choice anytime that the system or some third-party something will need to run PS but will not need a specific version of it.
I want to set the system so that in those cases it will be PS7 to be used.

And when PS5 is specifically needed, it should be that to run.

Is this possible and how?
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
Btw my Powershell 5.1 32bit isn't working.
Not to open a new thread just for that I'll ask here: is there a way to repair it or reinstall it?
I only find WMF but it's for other Windows.
I didn't find any download of PS5.1 or WMF5.1 for Windows11.
Maybe a DISM command to repair specifically PS5.1 without having to do the whole restorehealth?
Or WinGet?

If anybody knows, let me know (y)
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
Anyway I don't want to "force" PS7 always.
I want it to be the preferred choice anytime that the system or some third-party something will need to run PS but will not need a specific version of it.
Thousands of scripts exist that assume the default is PowerShell.exe and will break with pwsh.exe. Pwsh.exe should never be set as the default for all scripts. If a script is written to only work with pwsh.exe it will usually check the version (or at least it will be mentioned in a readme). You won't often find it the other way around.

As already mentioned, it's fine to set PowerShell Core as your default for Terminal.
 
Last edited:

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
Thousands of scripts exist that assume the default is PowerShell.exe and will break with pwsh.exe. Pwsh.exe should never be set as the default for all scripts.
I think that we might be talking of different things without realizing, because we have different level of knowledge about Windows.

Let's bring out the things we take for granted, so that we can check if the other person takes for granted the same things.

I take for granted that:
  • If a script specifically needs PowerShell.exe or Pwsh.exe it will specifically ask for it (and I'm not trying to change or bypass this, nor force something else)
  • If a script does NOT specifically need PowerShell.exe or Pwsh.exe it won't mind if I run it on Pwsh.exe
  • It's possible to set the system so that those scripts which do NOT specifically need one of the two PS will use Pwsh, without preventing those script which specifically need PowerShell from using PowerShell
If any of that is not correct, let me know.
Otherwise I'd still want to have a way to achieve what written in the last point, as it would not create any issue to e.g. scripts like your WinSetView (which would still be able to "call" PowerShell.exe -hopefully soon the 64bit version).
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
If a script specifically needs PowerShell.exe or Pwsh.exe it will specifically ask for it
Not correct. Most PowerShell scripts will get interpreted by whatever version of PowerShell is the default for running PS1 files. Of course, if the script is run by another process, that process can specify powershell.exe or pwsh.exe but it doesn't have to. Since PowerShell.exe existed long before pwsh.exe, changing the default is guaranteed to be a problem at some point. It could only work correctly if pwsh.exe were 100% backwards compatible with powershell.exe. It definitely is not.
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
Not correct. Most PowerShell scripts will get interpreted by whatever version of PowerShell is the default for running PS1 files. Of course, if the script is run by another process, that process can specify powershell.exe or pwsh.exe but it doesn't have to. Since PowerShell.exe existed long before pwsh.exe, changing the default is guaranteed to be a problem at some point. It could only work correctly if pwsh.exe were 100% backwards compatible with powershell.exe. It definitely is not.
So, I can set PS7 as default in Terminal because terminal is only used manually but not "called" by scripts, but I can't set PS7 as default system wide because there isn't a way to do that without preventing scripts which need PS5 from using PS5?
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    LG Gram 17Z90Q
    CPU
    12th Gen Intel(R) Core(TM) i7-1260P, 2100 Mhz
    Memory
    16GB LPDDR5 SDRAM
    Graphics Card(s)
    Intel(R) Iris(R) Xe
    Hard Drives
    Crucial T500 1TB + 2TB
    Mouse
    Logitech MX Master 3S
    Internet Speed
    Cable, 1000Mbit/s
So, I can set PS7 as default in Terminal because terminal is only used manually but not "called" by scripts, but I can't set PS7 as default system wide because there isn't a way to do that without preventing scripts which need PS5 from using PS5?
Yup.
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
Back
Top Bottom