1
00:00:01,040 --> 00:00:04,050
The last thing I want to show you is a special hashtable

2
00:00:04,050 --> 00:00:06,680
called PS default parameter values.

3
00:00:06,680 --> 00:00:10,340
It exists automatically whenever you start PowerShell.

4
00:00:10,340 --> 00:00:12,640
By default, it has nothing in it.

5
00:00:12,640 --> 00:00:16,360
I'm going to add some entries and show you how this hashtable

6
00:00:16,360 --> 00:00:24,340
works and why you might want to use it.

7
00:00:24,340 --> 00:00:27,660
So I'm going to create an entry in PS default parameter values.

8
00:00:27,660 --> 00:00:31,460
The key takes the format of the name of the cmdlet,

9
00:00:31,460 --> 00:00:36,240
in this case, Get‑WinEvent, a colon, and then the name of the parameter,

10
00:00:36,240 --> 00:00:38,250
and because I've got those that colon in there,

11
00:00:38,250 --> 00:00:41,940
I'm putting this in double quotes, comma,

12
00:00:41,940 --> 00:00:45,240
and then the value is system.

13
00:00:45,240 --> 00:00:51,040
Get‑WinEvent has a parameter Logname, which is expecting the name of a event log.

14
00:00:51,040 --> 00:00:55,370
If I don't specify anything, I want system to be used by default.

15
00:00:55,370 --> 00:00:58,540
Let me add another entry here.

16
00:00:58,540 --> 00:01:01,750
So I'm going to add for Get‑WinEvent, using the MaxEvents parameter,

17
00:01:01,750 --> 00:01:05,600
I'm going to use a value of 10,

18
00:01:05,600 --> 00:01:12,640
and there you can see the current contents of PS default parameter values.

19
00:01:12,640 --> 00:01:15,730
I don't have to do anything special, I'm not splatting here,

20
00:01:15,730 --> 00:01:20,240
all I have to do is run the cmdlet like Get‑WinEvent.

21
00:01:20,240 --> 00:01:23,700
PowerShell will use the default values, in this case,

22
00:01:23,700 --> 00:01:30,540
gives me the 10 most recent entries from the system event log.

23
00:01:30,540 --> 00:01:33,520
Now I can specify different values, for example,

24
00:01:33,520 --> 00:01:36,210
and with the application log and a max value of one,

25
00:01:36,210 --> 00:01:42,840
so the PS default parameters are not used in that particular case.

26
00:01:42,840 --> 00:01:47,290
If I need to, I can modify it, this is an easy way to do it,

27
00:01:47,290 --> 00:01:50,370
and here, I'm like using the square brackets so I can say,

28
00:01:50,370 --> 00:01:54,440
you know what, for now on, I want the Maxevents value to be 5.

29
00:01:54,440 --> 00:01:59,140
Now when I run Get‑WinEvent, pick a different log,

30
00:01:59,140 --> 00:02:01,810
I don't have to specify ‑Maxevents,

31
00:02:01,810 --> 00:02:05,970
PowerShell will use whatever is in PS default parameter values,

32
00:02:05,970 --> 00:02:09,140
and I get my five entries.

33
00:02:09,140 --> 00:02:12,190
PS default parameter values is something that you most

34
00:02:12,190 --> 00:02:14,940
likely will set in your PowerShell profile,

35
00:02:14,940 --> 00:02:19,760
although sometimes it kind of gets in the way so you can disable it temporarily.

36
00:02:19,760 --> 00:02:24,080
To do that, you need to add an entry, and this is one way to do it,

37
00:02:24,080 --> 00:02:27,480
called disabled and give it a value of true.

38
00:02:27,480 --> 00:02:34,640
The hashtable still exists, but PowerShell will not use it.

39
00:02:34,640 --> 00:02:35,690
When I run Get‑WinEvent,

40
00:02:35,690 --> 00:02:39,720
I get an error because I did not specify a value for the log names,

41
00:02:39,720 --> 00:02:45,140
that kind of shows me that PS default parameter values was not being used.

42
00:02:45,140 --> 00:02:46,540
If I want to re‑enable it,

43
00:02:46,540 --> 00:02:54,840
I can just set the disabled key and give it a value of false.

44
00:02:54,840 --> 00:03:00,640
You can also clear all the entries from the hashtable.

45
00:03:00,640 --> 00:03:04,440
The hashtable still exists, but it has nothing in it.

46
00:03:04,440 --> 00:03:07,650
I use PS default parameter values all the time in my

47
00:03:07,650 --> 00:03:11,230
PowerShell profile and it makes my work with PowerShell so

48
00:03:11,230 --> 00:03:14,480
much faster and so much easier, once again,

49
00:03:14,480 --> 00:03:19,380
a help topic that you should take a look at to learn more about PS default

50
00:03:19,380 --> 00:03:24,140
parameter values and why you might want to use them.

51
00:03:24,140 --> 00:03:27,200
And that brings us to the end of the module.

52
00:03:27,200 --> 00:03:30,840
We looked at working with arrays and hashtables.

53
00:03:30,840 --> 00:03:34,490
These are things that PowerShell uses everywhere and you will use them all the

54
00:03:34,490 --> 00:03:36,950
time so you have to know the difference between the two,

55
00:03:36,950 --> 00:03:38,610
how to create them, how to manipulate them,

56
00:03:38,610 --> 00:03:41,110
and how to use them in PowerShell.

57
00:03:41,110 --> 00:03:43,670
I've given you a lot of help links to look at,

58
00:03:43,670 --> 00:03:46,840
I encourage you to do that, it is definitely worth your time.

59
00:03:46,840 --> 00:03:48,840
So that's it for now.

60
00:03:48,840 --> 00:03:49,370
Again,

61
00:03:49,370 --> 00:03:56,000
take a quick break and then come on back and let's look at more about what we can learn about the PowerShell language.

