Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a Powershell Script to run a specific Version

I have both PowerShell 5.1 and PowerShell 7.0 on my computer. How can I enforce a mandatory version (a specific version, not a minimum or maximum version #) of PowerShell for a given script (in this case, PowerShell 7.0)?

like image 445
Nathan Levis Avatar asked Sep 03 '26 23:09

Nathan Levis


1 Answers

another option is to use #Requires statement

#Requires -Version 7.0

here is the reference from Microsoft support

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires

like image 111
Vital Avatar answered Sep 06 '26 14:09

Vital



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!