Out-Printer

Send output to a printer.

Syntax
      Out-Printer [[-name] string] [-inputObject psobject] [CommonParameters]

Key
   -name string
        The printer name, if omitted will go to default printer.

   -inputObject psobject
        The object to be sent to the printer {may be piped}

Standard Aliases for Out-Printer: lp

The final part of displaying PowerShell output is a hidden background call to an Output cmdlet, by default as the last part of the execution process PowerShell calls the default output cmdlet which is typically Out-Host.

Examples

Print a text file:

PS C:\> Get-Content $pshome\about_signing.help.txt | Out-Printer

Print "Hello, World" to a specific printer:

PS C:\> "Hello, World" | out-printer "\\Server64\Prn86754"

Send the content of a variable to the default printer:

PS C:\> $myhelp = get-help -detailed get-wmiobject
out-printer -inputobject $myhelp

Cancel print Jobs:

PS C:\> Get-CIMinstance Win32_Printer -computerName "Server64" | Where {$_.Name -eq "My Printer"} | ForEach-Object { $_.CancelAllJobs() }

Print a file from Microsoft Word (which can apply formatting changes)

$WordObj = New-Object -ComObject Word.Application
$WordObj.Documents.Add('C:\test.txt') > $null
$WordObj.ActiveDocument.Content.Font.Size = 12
$WordObj.ActiveDocument.Content.Font.Name = "Verdana"

#Send To Default Printer
$WordObj.PrintOut()

#Close File without saving
$WordObj.ActiveDocument.Close(0)
$WordObj.quit()

“Next time you make a printout from your color laser printer, shine an LED flashlight beam on it and examine it closely with a magnifying glass. You might be able to see the small, scattered yellow dots printed there that could be used to trace the document back to you” ~ Jason Tuohey

Related PowerShell Cmdlets

Out-Default - Send output to default.
Out-File - Send command output to a file.
Out-GridView - Send output to an interactive table.
Out-Host - Send the pipelined output to the host.
Out-Null - Send output to null.
Out-String - Send output to the pipleline as strings.
Tee-Object - Send input objects to two places.
Equivalent bash command: redirection - Redirection and Process Substitution.


 
Copyright © 1999-2024 SS64.com
Some rights reserved