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}
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.
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-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
$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:
Out-Default - Send output to default
Out-File - Send command output to a file
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