Hi all,<\/p>\n
I’m after a PowerShell script that will do the following in order<\/p>\n
Search for all documents in C:\\Users%CurrentUsers%\\Downloads*.pdf<\/p>\n<\/li>\n
Print these pdf files to the default printer<\/p>\n<\/li>\n
Delete the files after the print job has been complete<\/p>\n<\/li>\n<\/ol>\n
Thank you for your assistance <\/p>","upvoteCount":6,"answerCount":10,"datePublished":"2024-02-02T13:11:03.000Z","author":{"@type":"Person","name":"ashleydillonchandler","url":"https://community.spiceworks.com/u/ashleydillonchandler"},"acceptedAnswer":{"@type":"Answer","text":"
Your errir is:<\/p>\n
At line:1 char:67\n+ ... \\adadmin\\Downloads\\*.pdf\" |ForEach-Object {Start-Process -Verb Print}\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException\n + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand\n<\/code><\/pre>\nThis is telling you that the code \"start-process -verb print) i invalid.The reason is that you also need to pass a file name so something like this might work:<\/p>\n
ForEach-Object {Print.exe $_.fullname}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2024-02-02T15:02:48.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/4","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},"suggestedAnswer":[{"@type":"Answer","text":"Hi all,<\/p>\n
I’m after a PowerShell script that will do the following in order<\/p>\n
\n- \n
Search for all documents in C:\\Users%CurrentUsers%\\Downloads*.pdf<\/p>\n<\/li>\n
- \n
Print these pdf files to the default printer<\/p>\n<\/li>\n
- \n
Delete the files after the print job has been complete<\/p>\n<\/li>\n<\/ol>\n
Thank you for your assistance
<\/p>","upvoteCount":6,"datePublished":"2024-02-02T13:11:03.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/1","author":{"@type":"Person","name":"ashleydillonchandler","url":"https://community.spiceworks.com/u/ashleydillonchandler"}},{"@type":"Answer","text":"
No problem, I’m sure we can assist you, but we wont write it for you, so please share with us, what you already have.<\/p>\n
What works and what does not.<\/p>","upvoteCount":1,"datePublished":"2024-02-02T13:39:11.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/2","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
I’m quite new to PowerShell so i do apologise . My current script that I’ve tried is the following<\/p>\n
Get-ChildItem “C:\\Users\\adadmin\\Downloads*.pdf” |<\/p>\n
ForEach-Object {Start-Process -Verb Print}<\/p>\n
This then asks for the file path again which i stated as \"C:\\Users\\adadmin\\downloads*.pdf \" which I would then assume should print everything with the file extension .pdf but it doesn’t and comes back with the following<\/p>\n
\" Start-Process : This command cannot be run due to the error: No application is associated with the specified file for
\nthis operation.
\nAt line:1 char:67<\/p>\n
\n- … \\adadmin\\Downloads*.pdf\" |ForEach-Object {Start-Process -Verb Print}<\/li>\n
- \n
<\/code><\/pre>\n<\/li>\n- CategoryInfo : InvalidOperation: (
[Start-Process], InvalidOperationException<\/li>\n - FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand\"<\/li>\n<\/ul>\n
I nailed this down to it has no default program to access the file so I installed adobe reader, set this as the default application for .pdf and this resolved the issue. My first problem is I’m having to manually input the file path again and unsure how to get around this.<\/p>\n
Secondly i am wanting this to wait until the document is printed and then delete the file<\/p>\n
I’m currently using the following<\/p>\n
C:\\users\\adadmin\\downloads*.pdf -force which deletes but does no checking or waiting.<\/p>\n
Current script layout is<\/p>\n
\"<\/p>\n
Get-ChildItem “C:\\Users\\adadmin\\Downloads*.pdf” |<\/p>\n
ForEach-Object {Start-Process -Verb Print}<\/p>\n
—manualy inputting file path again-- I want to automate this somehow<\/p>\n
Timeout 15 second ( this allows me the file time to process/print but im wanting a way to check if its printed before moving to the deletion process )<\/p>\n
Remove-Item -Path C:\\users\\adchandler\\downloads*.pdf -force<\/p>","upvoteCount":0,"datePublished":"2024-02-02T14:49:54.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/3","author":{"@type":"Person","name":"ashleydillonchandler","url":"https://community.spiceworks.com/u/ashleydillonchandler"}},{"@type":"Answer","text":"
As a tip, when posting code, please use the insert code </> option above your text box and specify the type of code, so it formats correctly, as per tfl’s reply.<\/p>","upvoteCount":0,"datePublished":"2024-02-02T15:06:50.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/5","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
Thank you very much for you input TFL. I added your recommendation and it now prints each time without fail!<\/p>\n
now I need to figure out how to wait until the document is printed and then have it delete the contents of the folder, what would be your recommendations ?<\/p>","upvoteCount":0,"datePublished":"2024-02-02T15:10:01.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/6","author":{"@type":"Person","name":"ashleydillonchandler","url":"https://community.spiceworks.com/u/ashleydillonchandler"}},{"@type":"Answer","text":"
Sorry about that Rod-IT i will make sure to do this next time !<\/p>","upvoteCount":0,"datePublished":"2024-02-02T15:11:08.000Z","url":"https://community.spiceworks.com/t/powershell-script-for-auto-print-and-delete-document/966362/7","author":{"@type":"Person","name":"ashleydillonchandler","url":"https://community.spiceworks.com/u/ashleydillonchandler"}},{"@type":"Answer","text":"