\nHow do I pass the path Variables to powershell? The path is not static it changes based on the day.<\/p>\n<\/blockquote>\n<\/aside>\n
can you give an example?<\/p>","upvoteCount":0,"datePublished":"2018-07-26T15:45:43.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
I left the SFTP stuff out since I really just want to print.<\/p>\n
For /f \"tokens=2-4 delims=/ \" %%a in ('date /t') do (set mydate=%%c-%%a-%%b)\nFor /f \"tokens=2-4 delims=/ \" %%a in ('date /t') do (set myyear=%%c)\nFor /f \"tokens=1-2 delims=/: \" %%a in ('time /t') do (set mytime=%%a%%b)\nmkdir F:\\IMPORT\\%myyear%\\%mydate%-%mytime%\nCrazy Proprietary download app here. /From :/ to:F:\\IMPORT\\%myyear%\\%mydate%-%mytime%\n\nI was thinking about adding something like this.\npowershell dir \"F:\\IMPORT\\%myyear%\\%mydate%-%mytime%\\*.pdf\" | ForEach-Object {Start-Process -FilePath $_.FullName -Verb Print} \n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-26T15:50:35.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/5","author":{"@type":"Person","name":"404error","url":"https://community.spiceworks.com/u/404error"}},{"@type":"Answer","text":"the exact format depends on how you need your date info formatted<\/p>\n
$dateinfo = Get-Date\n$myyear = $dateinfo.year\n$mydate = get-date $dateinfo -f MM.dd\n$mytime = get-date $dateinfo -f hh.mm.ss\n\n\"F:\\Meridian_Import\\AAL_IMPORT\\$myyear\\$mydate-$mytime\\*.pdf\"\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-26T16:13:10.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"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<\/p>\n
Powershell.exe -executionpolicy bypass -File \"F:\\Print_AAL.ps1\"\n<\/code><\/pre>\nThen here how I decided to print something.<\/p>\n
\n\n```\nGet-Date -uformat \"%Y\" | set-variable -Name MyYear\nGet-Date -uformat \"%Y-%m-%d\" | set-variable -Name MyDate\nf:\ncd F:\\IMPORT\\$MyYear\\$MyDate\n\ndir \"F:\\IIMPORT\\$MyYear\\$MyDate\\*.pdf\" | ForEach-Object {Start-Process -FilePath $_.FullName -Verb Print} \n```\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-26T20:59:24.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/7","author":{"@type":"Person","name":"404error","url":"https://community.spiceworks.com/u/404error"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Leif7217:<\/div>\n
\nI 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<\/p>\n
Powershell.exe -executionpolicy bypass -File \"F:\\Print_AAL.ps1\"\n<\/code><\/pre>\nThen here how I decided to print something.<\/p>\n
\n\n```\nGet-Date -uformat \"%Y\" | set-variable -Name MyYear\nGet-Date -uformat \"%Y-%m-%d\" | set-variable -Name MyDate\nf:\ncd F:\\IMPORT\\$MyYear\\$MyDate\n\ndir \"F:\\IIMPORT\\$MyYear\\$MyDate\\*.pdf\" | ForEach-Object {Start-Process -FilePath $_.FullName -Verb Print} \n```\n\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nCoolio :¬)<\/p>\n
Does that work?<\/p>","upvoteCount":0,"datePublished":"2018-07-26T21:09:57.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
I will have to check it in the morning.<\/p>","upvoteCount":0,"datePublished":"2018-07-26T21:12:35.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/9","author":{"@type":"Person","name":"404error","url":"https://community.spiceworks.com/u/404error"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Leif7217:<\/div>\n
\nI put this in the end of the batch script<\/p>\n<\/blockquote>\n<\/aside>\n
I don’t think you can just run PowerShell from a batchfile.<\/p>\n
PowerShell scripts are ending in .ps1<\/p>\n
Once the .bat is done, you can write it that it calls the ‘print.ps1’<\/p>","upvoteCount":0,"datePublished":"2018-07-26T21:14:17.000Z","url":"https://community.spiceworks.com/t/commandline-print-pdfs-from-folder/664368/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}}]}}
404error
(Leif7217)
July 26, 2018, 3:13pm
1
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
Neally
(Neally)
July 26, 2018, 3:17pm
2
404error
(Leif7217)
July 26, 2018, 3:44pm
3
How do I pass the path Variables to powershell? The path is not static it changes based on the day.
Neally
(Neally)
July 26, 2018, 3:45pm
4
404error
(Leif7217)
July 26, 2018, 3:50pm
5
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}
Neally
(Neally)
July 26, 2018, 4:13pm
6
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"
404error
(Leif7217)
July 26, 2018, 8:59pm
7
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}
```
Neally
(Neally)
July 26, 2018, 9:09pm
8
Leif7217:
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?
404error
(Leif7217)
July 26, 2018, 9:12pm
9
I will have to check it in the morning.
Neally
(Neally)
July 26, 2018, 9:14pm
10
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’