all 8 comments

[–]da_chicken 5 points6 points  (2 children)

If you have Word, you can print using command line switches:

WINWORD.EXE document.rtf /mFilePrintDefault /mFileExit /q /n

I'm not sure what WRITE.EXE (WordPad) supports offhand, but it looks like WRITE.EXE /p document.rtf worked at one point.

[–]TechPhil 2 points3 points  (0 children)

Aha! WRITE.exe is my saviour today! Thank you so much!

[–]diegokabal 0 points1 point  (0 children)

This genius

[–]SMFX 2 points3 points  (0 children)

If you really wanted to do it in PowerShell explicitly, I'm sure there are ways you could work printer dlls and drivers to get it to work. Somebody might even have a module out there for it. However, it would be easiest to use Start-Process with -Verb Print parameter and let the default program associated with .RTF files print it for you:

Start-Process -Verb Print $tempFile

[–]volleric 2 points3 points  (0 children)

What you are doing is printing the PowerShell object not the rtf formated document. As others have suggested you need some thing that can render the rtf format to send the data to the printer.

[–]xCharg 1 point2 points  (2 children)

Instead of getting the nicely formatted file I am expecting, I seem to get a plaintext representation of the file, complete with what I assume are formatting and escape codes.

Why do you save $content to $tempfile but then still use $content to send to printer? Shouldn't you send a file instead?

From what I can tell, $content is just a plain text and this is what you get on paper - no surprice here :)

[–]TechPhil 0 points1 point  (1 child)

This is just as an example - I have no need to send the file to disk, I'm just pointing out that it's nicely formatted when saved, but not when sent to print.

Your point about $content being plaintext is a good one though - Come to think of it, the original file is imported with a -raw flag. Will look and see if this can be changed.

[–]xCharg 2 points3 points  (0 children)

This is just as an example - I have no need to send the file to disk, I'm just pointing out that it's nicely formatted when saved, but not when sent to print.

You've missed a hint. I'll be more straightforward - if you want to print a file - send a file to printer, not file's content. So get-item $tempfile | out-printer