Quantcast
Channel: Greg's Blog » System Admin
Viewing all articles
Browse latest Browse all 24

Updated PowerShell script to loop through files for printing.

$
0
0

After finishing my script from the previous post I thought there has to be a better way to write this and reduce the lines of code.  Not that 5 separate lines is a lot.  But, if the list of items to print grew larger say to 15 documents, and was in different subdirectories then it might get complicated.  So, I set about trying to find a way to use the ForEach-Object cmd.  After some trial and error I have come up with this. 

$Directory = "\\SVR1\DATA\Reports\Trading\"

Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 10;$_} | kill }

 

This will loop through the “Trading” directory and all subdirectories and print out the pdf documents it finds.  The one thing I still want to refine is the ability to close out Acrobat.  Right now it closes Acrobat after printing each document only to reopen it again for the next document.  I will look into just closing it at the end one time.  But for now this is at least a decent working script I plan to get a lot of use out of. 


Filed under: PowerShell, Windows Server Tagged: acrobat, Powershell, printing

Viewing all articles
Browse latest Browse all 24

Trending Articles