#REQUIRES statements
It's no secret that some code has prerequisites that need to be met in order for it to work. In PowerShell, certain types of requirements can be specified in scripts using a #REQUIRES
statement. Although the #REQUIRES
statement looks like a comment (that is, it starts with #
), it is a statement to the engine that tells PowerShell not to run the script unless the requirements are met. As of PowerShell Version 4.0, the following options are available in a #REQUIRES
statement:
Option |
Parameters |
Notes |
---|---|---|
|
N[.N] (for example, 4.0) |
Required version of PowerShell engine |
|
PSSnapinName [–Version N[.N]] |
Required Snapin (with optional minimum version |
|
ModuleName[,ModuleName] or Hashtable |
Required modules to be loaded |
|
ShellID |
Required PowerShell Host (for example, Microsoft.PowerShellISE) |
|
none |
Required session privileges |
When the conditions of the #REQUIRES
statement are not met, or cannot be met, the...