Been working on some maintenance, cleanup, auditing, streamlining for a customer. During this workthrough, printjobs showed up and asking around they actually performed this task manually. Of course I would not hear of this and created a simple powershell script that would go through all print servers, look for jobs older than 7 days and delete them. All wrapped in standard remote powershell, so this can be run from a central batch server.
1: Make sure to add your printservers to the array.
2: This script requires remote powershell to work 🙂
3: You can change the number of days to reflect your own requirements.
$PrintServers = @("<PrintSRV01>","<PrintSRV02>", "<PrintSRV03>", "<PrintSRV04>") Foreach($Printserver in $PrintServers) { $Session = New-PSSession -Computername $PrintServer -Authentication Kerberos $SC = { $OldJobs = get-wmiobject -class "Win32_PrintJob" -namespace "root\CIMV2" | Where-Object { $_.StartTime -lt $($(Get-Date).addDays(-7)) } foreach ($job in $OldJobs) { $job.Delete() } } Invoke-Command -Session $Session -ScriptBlock $SC Remove-PSSession $Session }
Advertisements