I have script that downloads around 30 pdfs into a folder and then I have to print them manually. I would like to automate the printing of the PDF but I don’t see any way in windows to do that. Right now the script is completely in batch. Does anyone know of a tool or command to print all the items in a folder?

1 Spice up

have a read here:

https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/

How do I pass the path Variables to powershell? The path is not static it changes based on the day.

can you give an example?

I left the SFTP stuff out since I really just want to print.

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set myyear=%%c)
For /f "tokens=1-2 delims=/: " %%a in ('time /t') do (set mytime=%%a%%b)
mkdir F:\IMPORT\%myyear%\%mydate%-%mytime%
Crazy Proprietary download app here. /From :/ to:F:\IMPORT\%myyear%\%mydate%-%mytime%

I was thinking about adding something like this.
powershell dir "F:\IMPORT\%myyear%\%mydate%-%mytime%\*.pdf" | ForEach-Object {Start-Process -FilePath $_.FullName -Verb Print} 

the exact format depends on how you need your date info formatted

$dateinfo = Get-Date
$myyear   = $dateinfo.year
$mydate   = get-date $dateinfo -f MM.dd
$mytime   = get-date $dateinfo -f hh.mm.ss

"F:\Meridian_Import\AAL_IMPORT\$myyear\$mydate-$mytime\*.pdf"

I was very close, I rewrote the batch and ditched the time part of the folder namde I put this in the end of the batch script

Powershell.exe -executionpolicy bypass -File "F:\Print_AAL.ps1"

Then here how I decided to print something.

 

```
Get-Date -uformat "%Y" | set-variable -Name MyYear
Get-Date -uformat "%Y-%m-%d" | set-variable -Name MyDate
f:
cd F:\IMPORT\$MyYear\$MyDate

dir "F:\IIMPORT\$MyYear\$MyDate\*.pdf" | ForEach-Object {Start-Process -FilePath $_.FullName -Verb Print} 
```

Coolio :¬)

Does that work?

I will have to check it in the morning.

I don’t think you can just run PowerShell from a batchfile.

PowerShell scripts are ending in .ps1

Once the .bat is done, you can write it that it calls the ‘print.ps1’