Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Best practices for script creation


As you are developing your scripts, there are standardized best practices that should be followed during the coding stage. These best practices provide robust and structured scripts, which will have predictable results. This section explores some of the recommendations for efficient PowerShell coding and provides guidance on how to avoid programming headaches.

Script structure

When you are creating scripts, you should adhere to a strict script structure. The structure of the script dictates the order of execution and how things are processed. It is recommended that you structure your scripts as shown here:

  1. Declare the script header: To start the scripting process, declare a header and include everything that is pertinent to the script. This may include a description, revision information, author, editor, and additional notes.

  2. Declare the input parameters: After the header, declare your input parameters if required by the script. Not only is this necessary...