1
00:00:01,040 --> 00:00:01,930
On occasion,

2
00:00:01,930 --> 00:00:07,260
you may want to get information out of PowerShell onto an actual hard copy like,

3
00:00:07,260 --> 00:00:10,640
yeah, actual paper that comes out of a printer.

4
00:00:10,640 --> 00:00:11,590
You could, of course,

5
00:00:11,590 --> 00:00:16,440
output it to a file using Out‑File and then open that file and print it off.

6
00:00:16,440 --> 00:00:19,170
But PowerShell has a native command to send

7
00:00:19,170 --> 00:00:23,940
PowerShell data directly to a printer, and that command is Out‑Printer.

8
00:00:23,940 --> 00:00:25,940
Let's take a look.

9
00:00:25,940 --> 00:00:30,840
As usual, let's explore the help to see if there's anything of interest in here.

10
00:00:30,840 --> 00:00:35,740
So as we probably figured out, this command will send output to a printer.

11
00:00:35,740 --> 00:00:39,010
It looks like we can specify the name of the printer and also,

12
00:00:39,010 --> 00:00:40,940
as per all of the other out cmdlets,

13
00:00:40,940 --> 00:00:44,450
you can use the InputObject parameter to specify the data

14
00:00:44,450 --> 00:00:46,940
that this command is going to work with.

15
00:00:46,940 --> 00:00:48,550
Under the description here,

16
00:00:48,550 --> 00:00:51,940
you'll note it will send to the default printer if you don't specify a

17
00:00:51,940 --> 00:00:55,940
name or an alternate printer if you do specify the name.

18
00:00:55,940 --> 00:00:59,830
Now because I can't easily show you an actual piece of paper

19
00:00:59,830 --> 00:01:02,300
coming out of my printer in the office here,

20
00:01:02,300 --> 00:01:05,440
and I don't have that printer set up on this machine anyway,

21
00:01:05,440 --> 00:01:08,890
I'm going to use a printer that we'll save as a PDF file.

22
00:01:08,890 --> 00:01:13,040
But I just need you to use some imagination that instead of being a PDF file,

23
00:01:13,040 --> 00:01:16,640
that the text is actually being sent to a real printer.

24
00:01:16,640 --> 00:01:20,890
So I'll run Get‑Printer, and on this Windows 10 machine by default,

25
00:01:20,890 --> 00:01:23,880
there's a printer here named Microsoft Print to PDF.

26
00:01:23,880 --> 00:01:25,960
And if you haven't used this before,

27
00:01:25,960 --> 00:01:28,990
you can literally just print to it as if it were a physical printer,

28
00:01:28,990 --> 00:01:32,940
but it will allow you to save the document as a PDF file.

29
00:01:32,940 --> 00:01:38,180
Let's run our trusty Get‑Process and pipe that to Out‑Printer. And I'm not

30
00:01:38,180 --> 00:01:42,040
actually sure what my default printer currently is, so I'll use the name

31
00:01:42,040 --> 00:01:46,640
parameter to specify the Microsoft Print to PDF printer.

32
00:01:46,640 --> 00:01:50,370
If this were a physical printer, that would now simply start getting printed

33
00:01:50,370 --> 00:01:54,190
out on a sheet of paper. But I'm going to get a prompt you to save this as a

34
00:01:54,190 --> 00:01:59,620
PDF file. Let me drop it in the C docs folder, and I'll call the file

35
00:01:59,620 --> 00:02:05,460
process.pdf. If I open that folder in Windows Explorer and then I'll just

36
00:02:05,460 --> 00:02:10,510
open up the PDF file in Microsoft Edge here as I don't have a dedicated PDF

37
00:02:10,510 --> 00:02:14,340
reader on this machine, and there you have it.

38
00:02:14,340 --> 00:02:18,140
The default output of Get‑Process has been printed.

39
00:02:18,140 --> 00:02:20,900
If we go back to the PowerShell console briefly,

40
00:02:20,900 --> 00:02:22,280
I do want to mention that,

41
00:02:22,280 --> 00:02:26,260
as per the other Out cmdlets, you can format the data first.

42
00:02:26,260 --> 00:02:29,670
So if we wanted to print this as a list, we can pipe that across to

43
00:02:29,670 --> 00:02:33,940
format‑list first and then send that to Out‑Printer.

44
00:02:33,940 --> 00:02:44,000
I'll call this one process2.pdf, and then we can open that up. And sure enough this time, we do have a list view that's been printed off.

