Two ways of checking PowerShell version

If your script needs a certain version of PowerShell you can check this in your script.

The easy easy way is to use #Requires.

This way you get an error message if the script is runned from a lower PowerShell version then what you have stated.

Will get this message on Windows PowerShell 5.1:

But If I have a module that does not work on PowerShell core 6.2 then I can do like this instead:

And then the script will only work on PowerShell 5.1

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.