Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # file named = Printer_KeepAlive.ps1
- <#
- i have a printer that glitches if it aint used at least once a week.
- this script prints the current date & time to the designated printer at a randomized
- location on the page. that means i can read what's been printed and be somewhat
- confident that it's working properly.
- the reason for the random location is that i have two paper trays for different uses.
- one is loaded new sheets and is used for new print jobs. the other is loaded with
- used - but mostly blank - sheets and is used for these keep-alive prints. randomizing
- the print location lets me re-use the sheets more often. the 2nd tray is the one i
- leave in place. [*grin*]
- i have task scheduler run it every monday morning at 6am.
- #>
- # if you don't know the name[s] of your printer[s], run the following line in a PS console window.
- #Get-WmiObject win32_printer | Select-Object name,default
- #
- # that will show you the installed printers and which is set as the default.
- # pick the printer you want and put it's name in the "$PrinterName" variable below.
- # if you are confident that your default printer won't get changed,
- # swap the "#" between the start of these two lines.
- #$PrinterName = ""
- $PrinterName = "Samsung ML-2855 Series PCL6"
- $DateStamp = (Get-Date -format F).ToString()
- # these numbers work for my printer and are somewhat conservative.
- # you can pro'ly make them somewhat larger IF you test the new numbers carefully.
- $CharsPerLine = 70
- $LinesPerPage = 60
- $MaxSpacesOver = $CharsPerLine - $DateStamp.Length
- $SpaceChar = " "
- $LineFeedChar = "`n"
- $SpacesOver = $SpaceChar * (Get-Random (0..$MaxSpacesOver))
- $LinesDown = $LineFeedChar * (Get-Random (0..$LinesPerPage))
- $WhatToPrint = (-join ($LinesDown, $SpacesOver, $DateStamp))
- # printing with a blank printer name _works_, but it makes me nervous.
- # that's why this test exists.
- if ($PrinterName -eq "")
- {
- Out-Printer -InputObject $WhatToPrint
- }
- else
- {
- Out-Printer -name $PrinterName -InputObject $WhatToPrint
- }
Add Comment
Please, Sign In to add comment