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

Deciding the best container for your scripts


When you are scripting, it is important to put consideration into what kind of container you will be using. Sometimes the simplicity of creating a singular variable and updating that variable is less complex than creating an array or hash table to search through. At other times, it may be more efficient to pull the whole dataset and use individual pieces of that data within your script.

Single-line variables can be used for:

  • Math operations that require calculations of single or multiple values

  • Catching single-line output from executing a non-PowerShell command

  • Tracking current position in a loop like "percent complete"

Arrays are best used for:

  • Storing a list of items for individual processing within a script

  • Dumping error information from a PowerShell cmdlet

Hashes are best used for:

  • Mapping data from one value to another value

  • Data that requires frequent searching, updating, or building during script execution

  • Storing multiple values of correlated data like user object attributes