1
00:00:00,940 --> 00:00:01,680
First up,

2
00:00:01,680 --> 00:00:06,240
let's talk about arrays. An array is a data structure that's

3
00:00:06,240 --> 00:00:10,840
designed to hold some collection or group of items,

4
00:00:10,840 --> 00:00:14,850
items, which in our case, is going to be PowerShell objects can be all of the

5
00:00:14,850 --> 00:00:19,140
same type or of different types. Although, as a general rule,

6
00:00:19,140 --> 00:00:23,530
we'll be working with arrays that contain objects of all of the same type,

7
00:00:23,530 --> 00:00:26,040
but that is not a requirement.

8
00:00:26,040 --> 00:00:29,790
You may also hear people refer to arrays as collections.

9
00:00:29,790 --> 00:00:33,440
Technically, from a programmatic standpoint, there is,

10
00:00:33,440 --> 00:00:37,440
I believe, a distinction between an array and a collection,

11
00:00:37,440 --> 00:00:40,370
but for our purposes, these terms are, in essence,

12
00:00:40,370 --> 00:00:46,040
interchangeable. Arrays and collections are the same thing.

13
00:00:46,040 --> 00:00:47,240
So as I said,

14
00:00:47,240 --> 00:00:52,040
an array is just a collection of things. Now in PowerShell,

15
00:00:52,040 --> 00:00:54,940
PowerShell is writing objects to the pipeline.

16
00:00:54,940 --> 00:00:58,200
It can create one object, or it might write multiple objects.

17
00:00:58,200 --> 00:01:01,030
All of those things can be saved into a variable, and

18
00:01:01,030 --> 00:01:03,190
that variable, then becomes an array.

19
00:01:03,190 --> 00:01:06,500
So the array is just a collection of things.

20
00:01:06,500 --> 00:01:11,100
You can also manually initialize an empty array and then add items to it

21
00:01:11,100 --> 00:01:15,440
programmatically, either using some operators that we'll look at or for each,

22
00:01:15,440 --> 00:01:18,530
or you'll see the different ways that we can do that.

23
00:01:18,530 --> 00:01:22,100
So arrays, nothing complicated here. It's just a collection of

24
00:01:22,100 --> 00:01:26,240
things. And here is how easy it is to create an array.

25
00:01:26,240 --> 00:01:30,140
Any comma‑separated list, PowerShell would treat as an array,

26
00:01:30,140 --> 00:01:32,670
So I have three numbers separated by commas.

27
00:01:32,670 --> 00:01:38,340
Save the results to $a, $a is an array of the numbers 3, 5, 9.

28
00:01:38,340 --> 00:01:42,880
If you type $a, PowerShell will automatically unroll or

29
00:01:42,880 --> 00:01:45,520
display the results of the array, and you can see the

30
00:01:45,520 --> 00:01:48,040
results listed there vertically.

31
00:01:48,040 --> 00:01:51,210
You don't have to do anything programmatic or scripting

32
00:01:51,210 --> 00:01:53,360
in order to see what's in the array.

33
00:01:53,360 --> 00:01:56,110
Now there are some things that you can do, which we'll get to in a

34
00:01:56,110 --> 00:01:59,080
moment, to access individual elements of an array,

35
00:01:59,080 --> 00:02:00,910
but to just see the entire array,

36
00:02:00,910 --> 00:02:05,940
just type the variable name, and PowerShell will handle the rest.

37
00:02:05,940 --> 00:02:09,690
The array object itself really doesn't have any meaning other

38
00:02:09,690 --> 00:02:14,160
than account property we'll look at later. The objects in the

39
00:02:14,160 --> 00:02:15,340
array, that's what matters.

40
00:02:15,340 --> 00:02:23,000
So I pipe $a to get‑member. I can see that the type name of each of those objects is an Int32.

