Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

#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

–Version

N[.N] (for example, 4.0)

Required version of PowerShell engine

–PSSnapIn

PSSnapinName [–Version N[.N]]

Required Snapin (with optional minimum version #)

–Modules

ModuleName[,ModuleName] or Hashtable

Required modules to be loaded

–ShellID

ShellID

Required PowerShell Host (for example, Microsoft.PowerShellISE)

–RunAsAdministrator

none

Required session privileges

When the conditions of the #REQUIRES statement are not met, or cannot be met, the...