How to specify the requirements for executing PowerShell scripts (#Requires)
Method
Use #Requires
.
-Version
and -PSEdition
are likely to be used often.
Syntax
#Requires -PSEdition [Core|Desktop]
#Requires -Version <N>[.<n>]
#Requires -PSSnapin <PSSnapin-Name> [-Version <N>[.<n>]]
#Requires -Modules { <Module-Name> | <Hashtable> }
#Requires -ShellId <ShellId>
#Requires -RunAsAdministrator
Example: -Version
Example of how to make it work only with PowerShell 5.0 or later.
#Requires -Version 5.0
Example: -PSEdition
Example of making PowerShell work only with Core editions.
#Requires -PSEdition Core