Decorate Scripts with #requires Statements

by Feb 19, 2016

PowerShell supports a number of #requires statements. Technically they are comments but PowerShell checks the requirements, and if they are not met, it won't run a script. In addition, #requires statements tell you quickly what a script needs to run.

#requires -Modules PrintManagement
#requires -Version 3
#Requires -RunAsAdministrator

#requires statements need to be the first statements in a script, and they work only for saved scripts.

Twitter This Tip! ReTweet this Tip!