1
00:00:01,040 --> 00:00:06,140
Next, let me show you how to search for history using the PSReadLine module,

2
00:00:06,140 --> 00:00:11,440
which is installed with PowerShell and pretty much enabled by default.

3
00:00:11,440 --> 00:00:15,910
One thing you can do is do Ctrl+R and then bring up

4
00:00:15,910 --> 00:00:19,040
this backward search in your history.

5
00:00:19,040 --> 00:00:19,600
Now,

6
00:00:19,600 --> 00:00:24,090
PowerShell PSReadLine module will store your history actually in a

7
00:00:24,090 --> 00:00:30,620
text file that will persist across PowerShell sessions so that the

8
00:00:30,620 --> 00:00:34,370
next time you open up PowerShell you can still search your history

9
00:00:34,370 --> 00:00:35,840
with this technique.

10
00:00:35,840 --> 00:00:38,820
The up and down arrows and the history commands won't

11
00:00:38,820 --> 00:00:42,730
work until you run the command, but this approach will work.

12
00:00:42,730 --> 00:00:49,740
So I can say, let's do get‑, and you can see it already filling in, service.

13
00:00:49,740 --> 00:00:52,740
And if I find what I want, then I can just hit Enter.

14
00:00:52,740 --> 00:00:59,910
So that's really nice Ctrl+R, get‑process, like that.

15
00:00:59,910 --> 00:01:02,840
I do like that quite a bit.

16
00:01:02,840 --> 00:01:05,560
I'll show you something else here with PSReadLine,

17
00:01:05,560 --> 00:01:11,040
and that is a new feature that will allow you to get some prediction.

18
00:01:11,040 --> 00:01:17,240
So let's look at get‑module PSReadLine.

19
00:01:17,240 --> 00:01:20,540
I use tab completion to complete that value.

20
00:01:20,540 --> 00:01:24,400
So I'm running version 2.1 or later,

21
00:01:24,400 --> 00:01:27,840
which is what you're going to need in order for what I'm about to show you.

22
00:01:27,840 --> 00:01:29,850
There's a new feature that,

23
00:01:29,850 --> 00:01:32,990
as I'm recording this course, is still technically in

24
00:01:32,990 --> 00:01:35,290
beta, but I know it will be coming out,

25
00:01:35,290 --> 00:01:38,180
and I know it's something that you'll want to take advantage of, so I'm

26
00:01:38,180 --> 00:01:41,130
going to go ahead and include it in the course here.

27
00:01:41,130 --> 00:01:45,330
I have notes in the download file to show you how to update

28
00:01:45,330 --> 00:01:48,540
the module if you have an older version.

29
00:01:48,540 --> 00:01:50,300
So I'm going to run a command called

30
00:01:50,300 --> 00:01:57,190
Get‑PSReadLineOption. And it's kind of hard to see here,

31
00:01:57,190 --> 00:02:00,780
but there is InlinePredictionColor. And there's an

32
00:02:00,780 --> 00:02:04,440
anti‑escape sequence that is kind of hard to see.

33
00:02:04,440 --> 00:02:09,390
But what this is going to do is allow me to predict, based on my history,

34
00:02:09,390 --> 00:02:12,240
what command I want to run.

35
00:02:12,240 --> 00:02:15,640
Now, before I can use this, I need to turn this on.

36
00:02:15,640 --> 00:02:20,940
So I'm going to do Set‑PSReadLineOption.

37
00:02:20,940 --> 00:02:26,840
And I'm using tab complete.

38
00:02:26,840 --> 00:02:28,660
There's a PredictionSource parameter,

39
00:02:28,660 --> 00:02:32,340
and I'm going to use History. Eventually there'll be some other options here,

40
00:02:32,340 --> 00:02:37,580
but History is what I'm going to use. Now that it's turned on,

41
00:02:37,580 --> 00:02:41,220
lets clear the screen here, and if I start typing, and this

42
00:02:41,220 --> 00:02:44,740
may be hard to see on the screen, I'm going to fix this in a moment.

43
00:02:44,740 --> 00:02:51,960
So I typed get, and very faintly in that dark gray color is a

44
00:02:51,960 --> 00:02:54,110
prediction based upon what I have done.

45
00:02:54,110 --> 00:02:54,560
Well,

46
00:02:54,560 --> 00:02:59,790
that's impossible to read really for my demonstration

47
00:02:59,790 --> 00:03:02,870
purposes. And even if I wasn't demonstrating,

48
00:03:02,870 --> 00:03:03,820
that's really hard to read.

49
00:03:03,820 --> 00:03:08,130
So, I'm going to modify that color. And this is going to

50
00:03:08,130 --> 00:03:10,360
be done with an anti‑escape sequence.

51
00:03:10,360 --> 00:03:24,240
So let's do Set‑PSReadLineOption ‑Colors.

52
00:03:24,240 --> 00:03:28,350
I have a little benefit here because I've already done this before in

53
00:03:28,350 --> 00:03:33,250
preparation for the demo, I have this command in my demo history so

54
00:03:33,250 --> 00:03:36,240
I'm able to kind of cheat and get to it.

55
00:03:36,240 --> 00:03:40,740
So I'm going to change the output using this sequence,

56
00:03:40,740 --> 00:03:43,940
which will display it in a different color.

57
00:03:43,940 --> 00:03:47,440
So now let's clear the screen. Let's do get.

58
00:03:47,440 --> 00:03:50,530
Now you can see there's the get‑PSReadLineOption.

59
00:03:50,530 --> 00:03:56,200
I hit the right arrow key to complete that. Or let's say I wanted to

60
00:03:56,200 --> 00:04:07,140
Get‑Service. And I was just hitting Tab, and that auto completed it, but it

61
00:04:07,140 --> 00:04:08,820
‑‑‑ I must not have much there with Get‑Service.

62
00:04:08,820 --> 00:04:12,900
Let's do get, if you don't want it then you just

63
00:04:12,900 --> 00:04:16,150
can ignore it, get‑service bits.

64
00:04:16,150 --> 00:04:23,440
So if I do get‑service, there's bits, and I can back up.

65
00:04:23,440 --> 00:04:26,590
There'll be a future version that has another feature

66
00:04:26,590 --> 00:04:29,490
that will allow you to display a list,

67
00:04:29,490 --> 00:04:31,650
and then you can pick the one that you want.

68
00:04:31,650 --> 00:04:38,080
But this prediction with PSReadLine is going to be pretty handy. I'm still,

69
00:04:38,080 --> 00:04:41,420
to be honest with you, getting used to it and trying to get my learn new

70
00:04:41,420 --> 00:04:43,690
muscle memory in order to take advantage of it,

71
00:04:43,690 --> 00:04:47,990
but you will want to take a look at it when it is available.

72
00:04:47,990 --> 00:04:49,740
Actually, you can use it now.

73
00:04:49,740 --> 00:04:55,910
Once they release the next version of PSReadLine,

74
00:04:55,910 --> 00:04:59,580
I think everything will be baked in, and certainly by the next

75
00:04:59,580 --> 00:05:02,990
release of PowerShell, totally baked in.

76
00:05:02,990 --> 00:05:06,600
And this will be the way that we'll be using it to find

77
00:05:06,600 --> 00:05:09,570
what commands we ran from our history.

78
00:05:09,570 --> 00:05:15,000
And with that, let's go back to the slides. I want to talk about one other thing here.

