Out Printer - PowerShell


Overview

Out-Printer sends the contents of an object to a specified printer for printing. It is typically used to print text, images, or other data directly to a connected printer device.

Syntax

Out-Printer [-Name] <string> [-Copies] <int> [-Duplex] <string> [-FitToPage] [-Landscape] [-PrinterStatus] [-DelayProcessing] [-JobCount] <int>

Options/Flags

  • -Name: Specifies the name of the printer to use. Required.
  • -Copies: Sets the number of copies to print. Default is 1.
  • -Duplex: Controls double-sided printing. Can be “Simplex” (one-sided), “Vertical” (two-sided vertical), or “Horizontal” (two-sided horizontal). Default is “Simplex”.
  • -FitToPage: Scales the print output to fit the page size. Default is $false.
  • -Landscape: Orients the output in landscape mode ($true) or portrait mode ($false). Default is $false.
  • -PrinterStatus: Displays the current status of the specified printer. Default is $false.
  • -DelayProcessing: Delays the printing process until the next input is received. Default is $true.
  • -JobCount: Specifies the number of printing jobs to send to the printer. Default is 1.

Examples

Print a text file to a printer named “MyPrinter”:

Get-Content "MyTextFile.txt" | Out-Printer -Name "MyPrinter"

Print multiple copies of an image to a printer named “OfficePrinter”:

$Image = Get-Content -Path "MyImage.jpg" -Encoding Byte
Out-Printer -Name "OfficePrinter" -Copies 5 -InputObject $Image

Print a PDF file in landscape mode to a printer named “HomePrinter”:

Get-Content "MyPDF.pdf" | Out-Printer -Name "HomePrinter" -Landscape -FitToPage

Common Issues

  • Printer not found: Ensure that the specified printer name is correct and the printer is properly connected.
  • No paper in printer: Check the printer’s paper tray and ensure it contains sufficient paper.
  • Print job stuck: Monitor the printer status using the -PrinterStatus option and restart the print job or clear any errors.

Integration

Combine with Get-Printer: Use Get-Printer to retrieve information about available printers and pass it to Out-Printer for printing.

$PrinterInfo = Get-Printer
Out-Printer -Name $PrinterInfo.Name

Chain with ConvertTo-Html: Convert data to HTML and then print it using Out-Printer.

$Data | ConvertTo-Html | Out-Printer -Name "ReportPrinter"
  • Print-File: Saves the specified object as a file and sends it to the default printer.
  • Write-Host: Prints the specified object directly to the console.