Scripts and Requires

The Requires statement is valid only in scripts and may be used to restrict a script from running if certain conditions are not met. For example, a script may require administrative rights, or certain modules.

The Requires statement must be the first line in the script; comments and other code may not appear before it.

An example of the Requires statement is shown here:

#Requires -RunAsAdministrator -Modules @{ ModuleName = 'TLS'; ModuleVersion = '2.0.0' }

Notice that there is no space between the comment character, #, and the Requires keyword.

PowerShell includes help for the Requires statement:

Get-Help about_Requires

In a script, the Requires statement may be used to declare a need for administrative rights, or certain modules.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.88.249