Hi!
I’m trying to write script which allows me to print many files in a folder, but I’m receiving error message. I havo no idea what is wrong right there. Could you guys help me?

Code and Error


```
Get-ChildItem "C:\Users\mjaniszewski\Desktop\FAKTURYSIX\*.pdf" -Recurse
ForEach-Object {Start-Process $_.Name -Verb Print}

**Output:**
 Directory: C:\Users\mjaniszewski\Desktop\FAKTURYSIX\2016\101

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       07.08.2019     12:06         278659 16JISP2146220113 – KP.pdf
-a----       07.08.2019     12:05         392759 16JISP2146220113.pdf

 <b>[...]

now it is loading all the files and looks good but then I get this:</b>

Start-Process : Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Provide an argument th
at is not null or empty, and then try the command again.
At line:2 char:31
+ ForEach-Object {Start-Process $_.Name -Verb Print}
+                               ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Start-Process], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand
```

4 Spice ups

You just need to add a pipe between your Get-ChildItem and Start-Process commands - $_ is an automatic variable that means the current object in the pipeline, but without your objects being passed through the pipe it has a null/empty value:

Get-ChildItem "C:\Users\mjaniszewski\Desktop\FAKTURYSIX\*.pdf" -Recurse | ForEach-Object {
    Start-Process $_.FullName -Verb Print
}

Thanks for the response, but this does not solve the problem. Now I get this error, but I have *.pdf files in the folder. As you can see above, without pipe it was loading files correctly.

Start-Process : This command cannot be run due to the error: 
Nie można odnaleźć określonego pliku. (it means: "Can't find specified file.")

At line:2 char:17
+ ForEach-Object {Start-Process $_.Name -Verb Print}
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

@francishagyard2

Without the pipe you were seeing the results of the Get-ChildItem command printed back to the console but it was not being passed to the ForEach-Object command. To make sure it finds the file use the .FullName property as I did in my first post

OK, you are right and it looks that I’m closer to the solution, but there is still another error. If it matters I’m working on PC in office and it is connected to the printer through local server (Wi-Fi). Deafult printer is set to one I want.

Start-Process : This command cannot be run due to the error: 
Z określonym plikiem nie skojarzono dla tej operacji żadnej aplikacji. (it means: "No application has been associated with the specified file for this operation.")

At line:1 char:101
+ ... df" -Recurse | ForEach-Object {Start-Process $_.FullName -Verb Print}
+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

Looks like you just need to set an association for that file extension (pdf). On W10 go to Settings > Apps > Default Apps > (Scroll to bottom) > Choose default applications by file type. Look for PDF and try a different program, for reference I have Adobe Reader installed and using Start-Process with verb Print works for me:

PDFFileExtension.jpg

OK I found the solution. As I read some info about this error, it actually happens when there is a difference between the default behaviour of opening the file and the relative behaviour of opening the file. To fix this all I need to do is to set the default application for the .pdf file as Adobe Reader and I won’t receive this error anymore. Now it is perefectly working, many thanks!

Note: If you are looking for a faster way to print many (15 and more) files or folders I recommend to use Print Conductor – free to use and very intuitive. It is printing last page with some info about company after every task, but for me it’s not a big deal, you can always take paper away after last page.