I would be very grateful for assistance for what is a really simple query.
I am trying to solve a problem - I receive several emails a day that have a PDF attachment. I am familiar with Power Automate and have written a flow to grab the PDF and put it in to a folder.
This folder is my One Drive folder which is synchronized locally.
I have therefore managed to get to a stage where I have a local folder on my machine with a bunch of PDFs.
I want to use the task scheduler to run a powershell script every 15 minutes which will go in to the folder, send each file to the printer and then delete it.
I believe this will be done with the Get Items query initially. I have no experience with powershell and have tried to cobble together the basics this evening. I can use this query to successfully get a list of the files in the ISE software.
I am then getting stuck. I need to apply a foreach query I believe next, to send each returned file from the query to the printer (possibly an out-printer command from what I have researched). The next command in the for each area will be to delete the file.
Please can somebody be kind enough to put this together for me? It will be my default printer and I will be able to insert in the path. I’m hoping it is a 2 minute job for an expert, I am really struggling to learn the syntax.
Even if it would be just a one minute job … This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.
We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
BTW: For the vast majority of the cases you’re not the first one with a given task. I’m pretty sure when you use your favorite internet search engine you will find something you can adapt to your particular needs.
In case anybody stumbles across this post looking for a similar use case - when I was saving files from the Windows Mail app it was appending the following after the original attachment name “[XXXXX]” upon save, where the XXXXX is a string of numbers.
The square brackets seemingly represent wildcards and therefore in the ForEach area the Remove-Item was not working. This was resulting in the same file printing over and over on each run of the Task Scheduler.
I therefore replaced the -Path with -LiteralPath and this solved the problem.