Hi!
\nI’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?<\/p>\n
Code and Error<\/p>\n
\n```\nGet-ChildItem \"C:\\Users\\mjaniszewski\\Desktop\\FAKTURYSIX\\*.pdf\" -Recurse\nForEach-Object {Start-Process $_.Name -Verb Print}\n\n**Output:**\n Directory: C:\\Users\\mjaniszewski\\Desktop\\FAKTURYSIX\\2016\\101\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\n-a---- 07.08.2019 12:06 278659 16JISP2146220113 – KP.pdf\n-a---- 07.08.2019 12:05 392759 16JISP2146220113.pdf\n\n <b>[...]\n\nnow it is loading all the files and looks good but then I get this:</b>\n\nStart-Process : Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Provide an argument th\nat is not null or empty, and then try the command again.\nAt line:2 char:31\n+ ForEach-Object {Start-Process $_.Name -Verb Print}\n+ ~~~~~~~\n + CategoryInfo : InvalidData: (:) [Start-Process], ParameterBindingValidationException\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand\n```\n\n<\/code><\/pre>","upvoteCount":4,"answerCount":7,"datePublished":"2019-08-16T07:14:06.000Z","author":{"@type":"Person","name":"spiceuser-4vmmr","url":"https://community.spiceworks.com/u/spiceuser-4vmmr"},"acceptedAnswer":{"@type":"Answer","text":"
Advertisement
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<\/p>","upvoteCount":0,"datePublished":"2019-08-16T08:37:44.000Z","url":"https://community.spiceworks.com/t/powershell-script-to-batch-printing/725850/4","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi!
\nI’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?<\/p>\n
Code and Error<\/p>\n
\n```\nGet-ChildItem \"C:\\Users\\mjaniszewski\\Desktop\\FAKTURYSIX\\*.pdf\" -Recurse\nForEach-Object {Start-Process $_.Name -Verb Print}\n\n**Output:**\n Directory: C:\\Users\\mjaniszewski\\Desktop\\FAKTURYSIX\\2016\\101\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\n-a---- 07.08.2019 12:06 278659 16JISP2146220113 – KP.pdf\n-a---- 07.08.2019 12:05 392759 16JISP2146220113.pdf\n\n <b>[...]\n\nnow it is loading all the files and looks good but then I get this:</b>\n\nStart-Process : Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Provide an argument th\nat is not null or empty, and then try the command again.\nAt line:2 char:31\n+ ForEach-Object {Start-Process $_.Name -Verb Print}\n+ ~~~~~~~\n + CategoryInfo : InvalidData: (:) [Start-Process], ParameterBindingValidationException\n + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand\n```\n\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2019-08-16T07:14:06.000Z","url":"https://community.spiceworks.com/t/powershell-script-to-batch-printing/725850/1","author":{"@type":"Person","name":"spiceuser-4vmmr","url":"https://community.spiceworks.com/u/spiceuser-4vmmr"}},{"@type":"Answer","text":"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:<\/p>\n
Get-ChildItem \"C:\\Users\\mjaniszewski\\Desktop\\FAKTURYSIX\\*.pdf\" -Recurse | ForEach-Object {\n Start-Process $_.FullName -Verb Print\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-08-16T08:09:17.000Z","url":"https://community.spiceworks.com/t/powershell-script-to-batch-printing/725850/2","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},{"@type":"Answer","text":"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.<\/p>\n
Start-Process : This command cannot be run due to the error: \nNie można odnaleźć określonego pliku. (it means: \"Can't find specified file.\")\n\nAt line:2 char:17\n+ ForEach-Object {Start-Process $_.Name -Verb Print}\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException\n + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand\n<\/code><\/pre>\n