How can I check the PS version before the main form loads and show a MessageBox error if version is less than 5?
#Requires -Version 5 will produce a console error if I export the code and run in ISE, but I need an error in the GUI. This method causes the built EXE to immediately exit without any output if triggered.
I tried the following function at the top of Startup.pss.
if ($PSVersionTable.PSVersion.Major -lt 5) { [void][System.Windows.Forms.MessageBox]::Show("This aplication requires PowerShell 5 or greater.", "Error", 'OK', 'error') break }Unfortunately this still fails to trigger as PS4 errors with The 'class' keyword is not supported in this version of the language..
Is there a way to get a GUI error for PowerShell version before the rest of the script loads?
Thanks for your help
Product: PowerShell Studio 2015
Version: 4.2.89
Operating System: Windows 10 64-bit