The last thing I want to show you is a special hashtable
called PS default parameter values.
It exists automatically whenever you start PowerShell.
By default, it has nothing in it.
I'm going to add some entries and show you how this hashtable
works and why you might want to use it.
So I'm going to create an entry in PS default parameter values.
The key takes the format of the name of the cmdlet,
in this case, Get‑WinEvent, a colon, and then the name of the parameter,
and because I've got those that colon in there,
I'm putting this in double quotes, comma,
and then the value is system.
Get‑WinEvent has a parameter Logname, which is expecting the name of a event log.
If I don't specify anything, I want system to be used by default.
Let me add another entry here.
So I'm going to add for Get‑WinEvent, using the MaxEvents parameter,
I'm going to use a value of 10,
and there you can see the current contents of PS default parameter values.
I don't have to do anything special, I'm not splatting here,
all I have to do is run the cmdlet like Get‑WinEvent.
PowerShell will use the default values, in this case,
gives me the 10 most recent entries from the system event log.
Now I can specify different values, for example,
and with the application log and a max value of one,
so the PS default parameters are not used in that particular case.
If I need to, I can modify it, this is an easy way to do it,
and here, I'm like using the square brackets so I can say,
you know what, for now on, I want the Maxevents value to be 5.
Now when I run Get‑WinEvent, pick a different log,
I don't have to specify ‑Maxevents,
PowerShell will use whatever is in PS default parameter values,
and I get my five entries.
PS default parameter values is something that you most
likely will set in your PowerShell profile,
although sometimes it kind of gets in the way so you can disable it temporarily.
To do that, you need to add an entry, and this is one way to do it,
called disabled and give it a value of true.
The hashtable still exists, but PowerShell will not use it.
When I run Get‑WinEvent,
I get an error because I did not specify a value for the log names,
that kind of shows me that PS default parameter values was not being used.
If I want to re‑enable it,
I can just set the disabled key and give it a value of false.
You can also clear all the entries from the hashtable.
The hashtable still exists, but it has nothing in it.
I use PS default parameter values all the time in my
PowerShell profile and it makes my work with PowerShell so
much faster and so much easier, once again,
a help topic that you should take a look at to learn more about PS default
parameter values and why you might want to use them.
And that brings us to the end of the module.
We looked at working with arrays and hashtables.
These are things that PowerShell uses everywhere and you will use them all the
time so you have to know the difference between the two,
how to create them, how to manipulate them,
and how to use them in PowerShell.
I've given you a lot of help links to look at,
I encourage you to do that, it is definitely worth your time.
So that's it for now.
Again,
take a quick break and then come on back and let's look at more about what we can learn about the PowerShell language.