Skip to content

Instantly share code, notes, and snippets.

@megamorf
Last active January 1, 2016 10:07
Show Gist options
  • Save megamorf/0604e4fd5264c5213940 to your computer and use it in GitHub Desktop.
Save megamorf/0604e4fd5264c5213940 to your computer and use it in GitHub Desktop.
Printer Wake Up Script
# with different set of printer shares
.\WakeUpPrinters.ps1 -PrinterShareNames @('printer4_ShareName','printer5_ShareName','printer6_ShareName')
# with additional verbose output
.\WakeUpPrinters.ps1 -Verbose
[CmdletBinding()]
Param(
[ValidateNotNullOrEmpty()]
[string[]]$PrinterShareNames = @('printer1_ShareName','printer2_ShareName','printer3_ShareName')
)
$Date = Get-Date
if( @("Sunday","Saturday") -notcontains $Date.DayOfWeek)
{
if( ($Date.Hour -ge 8) -and ($Date.Hour -lt 17) )
{
foreach($PrinterShareName in $PrinterShareNames)
{
$Printer = Get-WmiObject win32_printer -Filter "ShareName='$PrinterShareName'"
Write-Verbose "$PrinterShareName - Status [$($Printer.PrinterStatus)]"
if($Printer.PrinterStatus -ne 4)
{
Write-Verbose "$PrinterShareName - Status not '4' - Printing test page..."
$Printer.PrintTestPage()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment