Next, let me show you how to search for history using the PSReadLine module,
which is installed with PowerShell and pretty much enabled by default.
One thing you can do is do Ctrl+R and then bring up
this backward search in your history.
Now,
PowerShell PSReadLine module will store your history actually in a
text file that will persist across PowerShell sessions so that the
next time you open up PowerShell you can still search your history
with this technique.
The up and down arrows and the history commands won't
work until you run the command, but this approach will work.
So I can say, let's do get‑, and you can see it already filling in, service.
And if I find what I want, then I can just hit Enter.
So that's really nice Ctrl+R, get‑process, like that.
I do like that quite a bit.
I'll show you something else here with PSReadLine,
and that is a new feature that will allow you to get some prediction.
So let's look at get‑module PSReadLine.
I use tab completion to complete that value.
So I'm running version 2.1 or later,
which is what you're going to need in order for what I'm about to show you.
There's a new feature that,
as I'm recording this course, is still technically in
beta, but I know it will be coming out,
and I know it's something that you'll want to take advantage of, so I'm
going to go ahead and include it in the course here.
I have notes in the download file to show you how to update
the module if you have an older version.
So I'm going to run a command called
Get‑PSReadLineOption. And it's kind of hard to see here,
but there is InlinePredictionColor. And there's an
anti‑escape sequence that is kind of hard to see.
But what this is going to do is allow me to predict, based on my history,
what command I want to run.
Now, before I can use this, I need to turn this on.
So I'm going to do Set‑PSReadLineOption.
And I'm using tab complete.
There's a PredictionSource parameter,
and I'm going to use History. Eventually there'll be some other options here,
but History is what I'm going to use. Now that it's turned on,
lets clear the screen here, and if I start typing, and this
may be hard to see on the screen, I'm going to fix this in a moment.
So I typed get, and very faintly in that dark gray color is a
prediction based upon what I have done.
Well,
that's impossible to read really for my demonstration
purposes. And even if I wasn't demonstrating,
that's really hard to read.
So, I'm going to modify that color. And this is going to
be done with an anti‑escape sequence.
So let's do Set‑PSReadLineOption ‑Colors.
I have a little benefit here because I've already done this before in
preparation for the demo, I have this command in my demo history so
I'm able to kind of cheat and get to it.
So I'm going to change the output using this sequence,
which will display it in a different color.
So now let's clear the screen. Let's do get.
Now you can see there's the get‑PSReadLineOption.
I hit the right arrow key to complete that. Or let's say I wanted to
Get‑Service. And I was just hitting Tab, and that auto completed it, but it
‑‑‑ I must not have much there with Get‑Service.
Let's do get, if you don't want it then you just
can ignore it, get‑service bits.
So if I do get‑service, there's bits, and I can back up.
There'll be a future version that has another feature
that will allow you to display a list,
and then you can pick the one that you want.
But this prediction with PSReadLine is going to be pretty handy. I'm still,
to be honest with you, getting used to it and trying to get my learn new
muscle memory in order to take advantage of it,
but you will want to take a look at it when it is available.
Actually, you can use it now.
Once they release the next version of PSReadLine,
I think everything will be baked in, and certainly by the next
release of PowerShell, totally baked in.
And this will be the way that we'll be using it to find
what commands we ran from our history.
And with that, let's go back to the slides. I want to talk about one other thing here.