Does anyone know how to delete the file after it prints? I have tried everything and it works if a manually run it but as soon as I put into a scheduled task it deletes the files before the next print.<\/p>\n
I was thinking another scheduled task with remove item but it got clunky and the timing was way off. I just want to print the pdf, then delete it.<\/p>","upvoteCount":5,"answerCount":4,"datePublished":"2021-01-12T18:50:29.000Z","author":{"@type":"Person","name":"jaysonsolberg","url":"https://community.spiceworks.com/u/jaysonsolberg"},"acceptedAnswer":{"@type":"Answer","text":"\n\n
<\/div>\n
RS091:<\/div>\n
\n
That works with one caveat. I cant figure out where to put kill to shutdown adobe. Send you a coffee!!<\/p>\n<\/blockquote>\n<\/aside>\n
maybe like so<\/p>\n
$Directory = \"\\\\servershare\\PDLabels\"\n\nGet-ChildItem -path $Directory -recurse -include *.pdf | \nForEach-Object {\n Start-Process -FilePath $_.fullname -Verb Print -Wait\n get-process *adobe* | stop-process -force\n remove-item $_.FullName -verbose -Force\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-01-12T20:53:40.000Z","url":"https://community.spiceworks.com/t/autoprint-powershell/787178/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"$Directory = \"\\\\servershare\\PDLabels\"\n\nGet-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 10;$_} | kill}\n<\/code><\/pre>\nDoes anyone know how to delete the file after it prints? I have tried everything and it works if a manually run it but as soon as I put into a scheduled task it deletes the files before the next print.<\/p>\n
I was thinking another scheduled task with remove item but it got clunky and the timing was way off. I just want to print the pdf, then delete it.<\/p>","upvoteCount":5,"datePublished":"2021-01-12T18:50:29.000Z","url":"https://community.spiceworks.com/t/autoprint-powershell/787178/1","author":{"@type":"Person","name":"jaysonsolberg","url":"https://community.spiceworks.com/u/jaysonsolberg"}},{"@type":"Answer","text":"
start-process has a ‘-wait’ property.<\/p>\n
why don’t you try to start the print with wait and then a delete?<\/p>\n
e.g.<\/p>\n
$Directory = \"\\\\servershare\\PDLabels\"\n\nGet-ChildItem -path $Directory -recurse -include *.pdf | \nForEach-Object {\n Start-Process -FilePath $_.fullname -Verb Print -Wait\n remove-item $_.FullName -verbose -Force\n}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2021-01-12T18:58:28.000Z","url":"https://community.spiceworks.com/t/autoprint-powershell/787178/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"That works with one caveat. I cant figure out where to put kill to shutdown adobe. Send you a coffee!!<\/p>","upvoteCount":0,"datePublished":"2021-01-12T20:20:36.000Z","url":"https://community.spiceworks.com/t/autoprint-powershell/787178/3","author":{"@type":"Person","name":"jaysonsolberg","url":"https://community.spiceworks.com/u/jaysonsolberg"}}]}}
$Directory = "\\servershare\PDLabels"
Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 10;$_} | kill}
Does anyone know how to delete the file after it prints? I have tried everything and it works if a manually run it but as soon as I put into a scheduled task it deletes the files before the next print.
I was thinking another scheduled task with remove item but it got clunky and the timing was way off. I just want to print the pdf, then delete it.
5 Spice ups
Neally
(Neally)
January 12, 2021, 6:58pm
2
start-process has a ‘-wait’ property.
why don’t you try to start the print with wait and then a delete?
e.g.
$Directory = "\\servershare\PDLabels"
Get-ChildItem -path $Directory -recurse -include *.pdf |
ForEach-Object {
Start-Process -FilePath $_.fullname -Verb Print -Wait
remove-item $_.FullName -verbose -Force
}
2 Spice ups
That works with one caveat. I cant figure out where to put kill to shutdown adobe. Send you a coffee!!
Neally
(Neally)
January 12, 2021, 8:53pm
4
maybe like so
$Directory = "\\servershare\PDLabels"
Get-ChildItem -path $Directory -recurse -include *.pdf |
ForEach-Object {
Start-Process -FilePath $_.fullname -Verb Print -Wait
get-process *adobe* | stop-process -force
remove-item $_.FullName -verbose -Force
}
1 Spice up