I have powershell 5.1 asdefault in windows 10 system, which supports 2.0 also. By passing "-version 2" I can use 2.0 powershell, but my requirement is to make 2.0 as default powershell version whenever I invoke a ps1 script. How to change the default powershell version?


PSv5 is part of the OS. So, no you cannot not do this. Many of the cmdlets on Win10 are specific to Win10 PSv5. So, even if you could do this, most of the cmdlets on the box would simply fail to work.

PSv2 is no longer supported, depreciated, and no longer being patched.

Windows PowerShell 2.0 Deprecation

Microsoft Ending Windows PowerShell 2.0 Support with Windows 10 Fall Creators Update

Future OS releases, it will be removed completely.

Why would you take this risk. MS has specifically said, that users should disable it and not use it. As has all of the risk focused industry. There is nothing that PSv2 provides that newer version cannot and there are a great many things that the newer versions provide the PSv2 cannot, and cannot be back ported.

You can always write your code to check for PS version installed and branch your code for the version you are targeting, with the cmdlets for that version, but this also requires you to have the list of cmdlets for all those legacy versions.

Leverage PSScriptAnalyzer for this, to help here. Note, PScriptAnalyzer will not work on v2 because it was never released for it.

Old PowerShell v2 code runs just fine on higher PS versions. A great many of the new cmdlets / modules / functions, will not run on v2.

Using PSScriptAnalyzer to check PowerShell version compatibility

The only reason PS2 is still there was backwards compat.

Resources for reasons not to use PSv2.

Detecting and Preventing PowerShell Downgrade Attacks

US Department of Defense

  • Thank you so much for the information! appreciate!Actually we have a special requirement , have to run the same powershell script on Win 7 as well as Win10. So now I think We need to upgrade our script to support PSv5 only and have to install OSv5 on win7. – Koyel Datta May 13 at 6:41
  • No worries, glad it was helpful. – postanote May 13 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.