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

Chapter 1. Variables, Arrays, and Hashes

PowerShell provides a variety of mechanisms to store, retrieve, and manipulate data used in your scripts. These storage "containers" are referred to as variables, arrays, and hashes. They can be used as containers to store strings, integers, or objects. These containers are dynamic as they automatically detect what type of data is being placed within them. Unlike other object-oriented languages, there is no need to declare the container prior to use. To declare one of these containers, you use the dollar sign ($) and the container name.

An example of a container would look like this:

$myVariable

During this chapter, you will learn the following concepts:

  • Variables

  • Arrays

  • Hashes

  • Deciding the best container for your scripts

When you are creating names for containers, it is industry best practice to use names that are representative of the data they are storing. While containers are not case sensitive in PowerShell, it is a common practice to use camelCase when writing container names. camelCase is achieved by keeping the first letter of the container lowercase and the subsequent first letters of each word capitalized. Some variations of camelCase permit the first letter to be capitalized. This formatting aids in easy reading of the containers.

An example of a container using camelCase would look like this:

$webServerIPAddress