First up,
let's talk about arrays. An array is a data structure that's
designed to hold some collection or group of items,
items, which in our case, is going to be PowerShell objects can be all of the
same type or of different types. Although, as a general rule,
we'll be working with arrays that contain objects of all of the same type,
but that is not a requirement.
You may also hear people refer to arrays as collections.
Technically, from a programmatic standpoint, there is,
I believe, a distinction between an array and a collection,
but for our purposes, these terms are, in essence,
interchangeable. Arrays and collections are the same thing.
So as I said,
an array is just a collection of things. Now in PowerShell,
PowerShell is writing objects to the pipeline.
It can create one object, or it might write multiple objects.
All of those things can be saved into a variable, and
that variable, then becomes an array.
So the array is just a collection of things.
You can also manually initialize an empty array and then add items to it
programmatically, either using some operators that we'll look at or for each,
or you'll see the different ways that we can do that.
So arrays, nothing complicated here. It's just a collection of
things. And here is how easy it is to create an array.
Any comma‑separated list, PowerShell would treat as an array,
So I have three numbers separated by commas.
Save the results to $a, $a is an array of the numbers 3, 5, 9.
If you type $a, PowerShell will automatically unroll or
display the results of the array, and you can see the
results listed there vertically.
You don't have to do anything programmatic or scripting
in order to see what's in the array.
Now there are some things that you can do, which we'll get to in a
moment, to access individual elements of an array,
but to just see the entire array,
just type the variable name, and PowerShell will handle the rest.
The array object itself really doesn't have any meaning other
than account property we'll look at later. The objects in the
array, that's what matters.
So I pipe $a to get‑member. I can see that the type name of each of those objects is an Int32.