On our primary windows 2003 print server we share about 500 printers. We typically have about 50 stuck print jobs. Although far from the end of the world it bugs the hell out of me and I tend to end up spending 30 odd mins a week searching for and deleting stuck jobs.
What I would really like is a script to delete all print jobs on all printers older than 24 hours.
Coming from a UNIX background I find windows scripting pretty confusing. Any advice on how I can get started with this task would be appreciated. Any complete solutions would be amazing. ;)
Cheers,
Mat.
This should be fairly simple to do in Powershell. You will find powershell a little more to your liking coming from *nix. You will however be working with WMI, which is truely a blessing and a curse.
Some example code that does what you want (NOT TESTED):
Basically you will just need to get all objects from WMI where the Start Time is less than now - 24 hours.
This could be your strategy. Stop the spooler service, delete all old files and restart the service.
Write this script code in a text file and name it "DeleteOldQueuedFile.vbs":
Write a batch file which you could schedule as a nightly job:
If you go into the windows 2003 resource kit, there is a tool designed to do this called Cleanspl.exe.
Resource Kit: mircosoft url /downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
or you can script it:
Not sure if the accepted answer was working at the time but on Server 2012 R2 and 2016 it would not work anymore.
The property is now TimeSubmitted and it cannot be compared to a DateTime without converting from a WMI Timeobject. Also the Delete method cannot be called like in the accepted answer because of overloads. So an updated Version would be: