I am trying to get a script written which will pull the document name sent to the print queue and enter it into a text file. Anyone able to help with this?
-
Scripting Help!
-
Hello @Stacy-Hollins ,
The PowerShell cmdlet Get-PrintJob should work. Maybe something like this:
Get-PrintJob -PrinterName "HP940571 (HP ENVY Photo 7100 series)" | Select DocumentName > jobs.txt
You would need to replace the name of the printer of course, and can change the path and name of the output file.
If you have multiple printers, you could use a for each loop to cycle through all of them (or some of them). If you need the name of the printer(s), use:
Get-Printer
The name of the file included the application name, you can truncate the name if this causes problems.
Hope this helps,
Mike Rodrick
Edutainer, ITProTV**if the post above has answered the question, please mark the topic as solved.
-
@Mike-Rodrick Thank you! That will work perfectly! Is there a way to have it not save duplicate names in the txt file? And even pop up a cmd block asking if you would like to continue with the print job if it is a duplicate?
-
You're welcome!
You can add the Get-Unique cmdlet to your script to filter out duplicates. It would look something like this:
Get-PrintJob -PrinterName "HP940571 (HP ENVY Photo 7100 series)" | Sort-Object | Select DocumentName | Get-Unique -AsString > UniquePrintJobs.txt
For this cmdlet to work, the results must be sorted first.
There is also a
-unique
parameter you can use withSort-Object
. It would look like this:Get-PrintJob -PrinterName "HP940571 (HP ENVY Photo 7100 series)" | Sort-Object -Property DocumentName -Unique | select DocumentName > UniquePrintJobs2.txt
Results are the same, as far as I can tell. There might be a performance difference if you were working with very large data sets.
As for adding a dialog box, that would be tricky. You would need to somehow run your script every time the user clicked print in an application, or maybe anytime a new job was added to the print queue. This would mean somehow creating a listener on the print queue, or modifying the applications. Not sure, I'd have to think about that one some more.
Hope this helps,
Mike Rodrick
Edutainer, ITProTV**if the post above has answered the question, please mark the topic as solved.