Out-Printer

Sending Output to a Printer with PowerShell: Meet Out-Printer

Welcome back to Wahmans PowerShell blog! Today, we’re exploring the Out-Printer cmdlet – a handy tool in the PowerShell toolkit that lets you send output directly to your printer. Whether you want to print logs, reports, or formatted tables right from your script, Out-Printer makes it seamless.

What is Out-Printer?

According to Microsoft Docs, the description for Out-Printer is:

Sends output to a printer.

Essentially, it acts like a pipe to your printer. Instead of sending output to the console, you send it to one of your installed printers. Let me show you how it works in practical scenarios.

Example 1: Printing a Simple Text String – (Beginner)

"Hello from PowerShell!" | Out-Printer

This is the simplest use-case. We output a string and pipe it into Out-Printer. Whatever is piped gets printed.

Example 2: Printing a List of Running Processes – (Intermediate)

Get-Process | Out-Printer

This command retrieves all current processes and sends the list to your default printer. You’ll get a hardcopy snapshot of your system’s current activity.

Example 3: Printing to a Specific Printer – (Advanced)

Get-Service | Out-Printer -Name "Microsoft Print to PDF"

Want to send output to a specific printer? Use the -Name parameter. In this example, we print the list of services to a virtual PDF printer. Remember to verify the printer name using Get-Printer.

Example 4: Formatting and Printing a Custom Report – (Power User)

$report = Get-EventLog -LogName System -Newest 10 | 
    Select-Object TimeGenerated, EntryType, Source, Message | 
    Format-Table -AutoSize
$report | Out-Printer -Name "Your Printer Name"

Here, we’re creating a custom report from the System event log, full of useful troubleshooting info. We format it nicely with Format-Table before printing. Replace “Your Printer Name” with the actual name.

Conclusion

That’s it for today’s dive into Out-Printer! Whether you’re sending simple strings or sophisticated reports, this cmdlet can simplify your printing workflow within PowerShell.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *