I am new to PS, and am looking to automate printing of files from a directory. I believe I've solved it for a 'real' printer, but in this case I am trying to flatten a .pdf using MS Print to PDF. I haven't been able to find any way to way to pass additional parameters (in this case, the output save location + file name)
Start-Process -file "C:\file.pdf" Verb -Print
As a workaround, I believe this will work to set the default printer (which Print uses) and a custom port (which can be set to a file folder)
Set-Printer -Name "Print to PDF" -Port "C:\OutputPDF\" [Edit: Adding ports can be restricted and does not appear to be a consistent workaround]
This works as long as Adobe is the default .pdf viewer which is an unideal, but acceptable limitation. This will open Adobe with a "Save As" dialog. I am looking to try to automate that final step and pass in a file name to automatically save as. So far I haven't seen an obvious flag that will allow this, and haven't been able to find a way to add input to the print verb or manipulate using the printmanagement PS commands.
This problem seems to be often asked, but no simple solution exists (e.g., not delving deep into multiple .Net classes)
https://learn.microsoft.com/en-us/powershell/module/printmanagement/set-printer?view=windowsserver2019-ps
https://learn.microsoft.com/en-us/answers/questions/503516/printing-using-the-printer-api.html
https://learn.microsoft.com/en-us/answers/questions/224327/print-pdf-to-another-pdf-with-powershell-to-flatte.html