Lee_Dailey

Printer_KeepAlive

May 28th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # file named = Printer_KeepAlive.ps1
  2.  
  3. <#
  4. i have a printer that glitches if it aint used at least once a week.
  5.  
  6. this script prints the current date & time to the designated printer at a randomized
  7.     location on the page. that means i can read what's been printed and be somewhat
  8.     confident that it's working properly.
  9.  
  10. the reason for the random location is that i have two paper trays for different uses.
  11.     one is loaded new sheets and is used for new print jobs. the other is loaded with
  12.     used - but mostly blank - sheets and is used for these keep-alive prints. randomizing
  13.     the print location lets me re-use the sheets more often. the 2nd tray is the one i
  14.     leave in place. [*grin*]
  15.  
  16. i have task scheduler run it every monday morning at 6am.
  17. #>
  18.  
  19. # if you don't know the name[s] of your printer[s], run the following line in a PS console window.
  20. #Get-WmiObject win32_printer | Select-Object name,default
  21. #
  22. # that will show you the installed printers and which is set as the default.
  23. # pick the printer you want and put it's name in the "$PrinterName" variable below.
  24.  
  25. # if you are confident that your default printer won't get changed,
  26. #   swap the "#" between the start of these two lines.
  27. #$PrinterName = ""
  28. $PrinterName = "Samsung ML-2855 Series PCL6"
  29.  
  30. $DateStamp = (Get-Date -format F).ToString()
  31.  
  32. # these numbers work for my printer and are somewhat conservative.
  33. #    you can pro'ly make them somewhat larger IF you test the new numbers carefully.
  34. $CharsPerLine = 70
  35. $LinesPerPage = 60
  36. $MaxSpacesOver = $CharsPerLine - $DateStamp.Length
  37.  
  38. $SpaceChar = " "
  39. $LineFeedChar = "`n"
  40.  
  41. $SpacesOver = $SpaceChar * (Get-Random (0..$MaxSpacesOver))
  42. $LinesDown = $LineFeedChar * (Get-Random (0..$LinesPerPage))
  43. $WhatToPrint = (-join ($LinesDown, $SpacesOver, $DateStamp))
  44.  
  45. # printing with a blank printer name _works_, but it makes me nervous.
  46. #     that's why this test exists.
  47. if ($PrinterName -eq "")
  48.     {
  49.     Out-Printer -InputObject $WhatToPrint
  50.     }
  51.     else
  52.     {
  53.     Out-Printer -name $PrinterName -InputObject $WhatToPrint
  54.     }
Add Comment
Please, Sign In to add comment