Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing with Powershell and files in folders

I have a script which does some onsite printing. It doesnt work too well at the moment as the below runs for various file types which are sent to a folder to print, but the problem is it will only print 1 document at a time.

Start-Process –FilePath “c:\tests\*.docx” –Verb Print

I had the idea of doing this to get around it:

    get-ChildItem "C:\Tests\*.docx" | `

    foreach-object {

    start-process -verb Print

}

This doesnt seem to work though. So then i tried this:

get-childitem "C:\Tests\*.xlsx" | `

foreach-object {

Start-Process -Filepath "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" –Verb Print }

Also no luck,

Returns this error:

Start-Process : This command cannot be run due to the error: No application is associated with the specified file for this operation.

I think i am maybe not visualing the process here. Any ideas at all anyone on how to achieve printing of every file in a folder via powershell?

Windows 7 64 bit and $PSVersion = 5.0

Thanks in advance

like image 381
Royston Avatar asked Apr 21 '16 14:04

Royston


People also ask

Can I print a list of documents in a folder?

Select all the files, press and hold the shift key, then right-click and select Copy as path. This copies the list of file names to the clipboard. Paste the results into any document such as a txt or doc file & print that. Then open notepad, open tempfilename, and print it from there.

How do I print a group of files in a folder?

Files selected with Ctrl. This is the easiest way to mark a few files for printing. To use this hotkey, simply click on the first file you want to select, then press the Ctrl key. While holding this key, click on all the other files you want to print.


1 Answers

You are very close, start-process needs the full path and name of the file:

Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print}

Using a foreach loop should help you too:

$files = Get-ChildItem "c:\tests\*.docx"

foreach ($file in $files){
    start-process -FilePath $file.fullName -Verb Print
}
like image 107
Kai Zhao Avatar answered Nov 10 '22 10:11

Kai Zhao