Send output to a printer.

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

   -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}

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

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.


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-WmiObject Win32_Printer -computerName "Server64" | Where {$_.Name -eq "My Printer"} | ForEach { $_.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

#Close File without saving

“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 Commands:

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 © SS64.com 1999-2018
Some rights reserved