1
00:00:01,040 --> 00:00:05,140
Let's continue looking at working with arrays in PowerShell.

2
00:00:05,140 --> 00:00:08,700
I'm going to create another array here, $n,

3
00:00:08,700 --> 00:00:13,940
and in $n I'm going to add a bunch of different types of objects.

4
00:00:13,940 --> 00:00:18,550
So I've got some strings, some numbers, and if I look at $n,

5
00:00:18,550 --> 00:00:21,110
alright, so you can see all of those elements in there.

6
00:00:21,110 --> 00:00:23,870
I'm doing this just to show you that you can have

7
00:00:23,870 --> 00:00:27,370
different types of objects in the same array.

8
00:00:27,370 --> 00:00:30,440
If I pipe $n to Get‑Member,

9
00:00:30,440 --> 00:00:34,140
Get‑Member is going to show me all of the object types, so

10
00:00:34,140 --> 00:00:41,040
you can see I have numbers and strings.

11
00:00:41,040 --> 00:00:44,650
So many times we work with arrays and want to test if

12
00:00:44,650 --> 00:00:50,840
values are in or contained in an array, and we can do that with some operators.

13
00:00:50,840 --> 00:00:53,040
So let's do ‑contains.

14
00:00:53,040 --> 00:00:59,970
I want to know if the string FOO is contained in $n, and it is True.

15
00:00:59,970 --> 00:01:04,040
This is not case sensitive.

16
00:01:04,040 --> 00:01:06,340
Does it contain xyz?

17
00:01:06,340 --> 00:01:10,040
No, it does not, so I get a value of False.

18
00:01:10,040 --> 00:01:13,240
You can also test the inverse.

19
00:01:13,240 --> 00:01:15,400
Does $n not contain xyz?

20
00:01:15,400 --> 00:01:19,040
And, of course, now I get a result of True.

21
00:01:19,040 --> 00:01:22,050
Now you can also turn this around and instead of using contains,

22
00:01:22,050 --> 00:01:24,630
you can test if something is in.

23
00:01:24,630 --> 00:01:28,570
So I can say, hey, is xyz in $n?

24
00:01:28,570 --> 00:01:32,340
Again, and the results are going to be True or False.

25
00:01:32,340 --> 00:01:38,740
And there's also reverse ‑notin, is xyz not in $n, and that is True.

26
00:01:38,740 --> 00:01:43,990
Whether you use ‑contains or notcontains or in or notin

27
00:01:43,990 --> 00:01:45,920
kind of depends upon the situation.

28
00:01:45,920 --> 00:01:51,180
Sometimes it makes more sense to be looking if it's contained, and other

29
00:01:51,180 --> 00:01:55,940
times it makes more sense to test if something is in.

30
00:01:55,940 --> 00:01:58,240
Let me give you a practical example.

31
00:01:58,240 --> 00:02:02,880
So I'm going to create a list array, or an array called list I should say,

32
00:02:02,880 --> 00:02:10,210
and it has rdp, searchapp, and spoolsv. And I'm going to run Get‑Process, and

33
00:02:10,210 --> 00:02:13,720
I'm going to filter. And there are other ways you could do this, so I'm going

34
00:02:13,720 --> 00:02:16,240
to do this with the operators here.

35
00:02:16,240 --> 00:02:21,500
So I'm going to filter processes, and I only want processes where the

36
00:02:21,500 --> 00:02:26,640
name property of the process is contained in $list.

37
00:02:26,640 --> 00:02:30,560
So if $list contains the process by name,

38
00:02:30,560 --> 00:02:33,540
then write that result to the pipeline.

39
00:02:33,540 --> 00:02:39,760
And sure enough, I get the rdpclip, SearchApp, and spoolsv in the result.

40
00:02:39,760 --> 00:02:47,040
And let's look at doing something with in.

41
00:02:47,040 --> 00:02:51,040
So I created an array called $allowed, and it has values that I have

42
00:02:51,040 --> 00:02:56,590
pulled from the Get‑SmbShare cmdlet. So here's what I want to do, I'm

43
00:02:56,590 --> 00:03:01,640
going to run Get‑SmbShare, and I'm going to check a computer name, and

44
00:03:01,640 --> 00:03:09,040
I want to know only those shares where the description of the share is

45
00:03:09,040 --> 00:03:11,530
not in $allowed.

46
00:03:11,530 --> 00:03:12,240
In essence,

47
00:03:12,240 --> 00:03:15,330
I want to find all the shares that have been set up that

48
00:03:15,330 --> 00:03:20,220
aren't in this list. And on prospero, you can see that there

49
00:03:20,220 --> 00:03:22,880
are shares for scripts and work.

50
00:03:22,880 --> 00:03:26,210
I could also have written that command using the contains or notcontains,

51
00:03:26,210 --> 00:03:34,000
it's just kind of whatever makes sense to you logically, that's the operator to use.

