Requires

You may have seen this at the top of scripts or modules

#Requires –Version 3

This will stop the script running if the PowerShell version is 2.0 or below.

Other options are available

#Requires –PSSnapin      can be used to force the loading of a snapin

#Requires –Modules     can be used to force importing of modules

#Requires –Shellid    controls which shells the script can run in.  Default PowerShell installs have the ISE and console

#Requires –RunAsAdminstrator  – script must be running in instance of PowerShell with elevated privileges

These provide a simple and easy way to control execution without lots of code. I particularly like the last one.

Advertisements
This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s