18 January 2016

Morning printer check list


I had support a lot of label datamax o'neil and laser network printers. Label printers worked in Thermal Mode and need be cleaned after print 10 000 labels. Printers have WEB interface. For check printers that need clean was made script. Started when you logon by schedule. Scanned all network printers, parsed label quantity and saved on csv file. Same this wersion of script was did in cycle type for online/offline status of printers for reaction on network issue or frozen printers.


$data =""
$outarray = @()
$site = 7275
$_ = @()
get-date
[string]$dir = Get-Location
Get-Content $dir\datamax_printer_database_$site.txt | ForEach-Object {
    #dcprb008.firm.com - format of label printer name. File datamax_printer_database_$site.txt have only "dcprb008"
        $status = @{ "ServerName" = $_ + ".firm.com""TimeStamp" = (Get-Date -format d/MMM/yy---HH:mm) }
        if ((Test-Connection $status["ServerName"-Count 3 -ea 0 -Quiet) -eq 'True')
            {
            [int]$status["ServerName"] = $status["ServerName"][6] + $status["ServerName"][7]
            $status["Results"] = "Up"
            $url="http://"+$status["ServerName"]+"/media.html"
            $content = (new-object System.Net.WebClient).DownloadString($url)
            if (($content -match 'clean.*?<td.width="187.*?">(.*?).in.</td>') -eq 'True')
                {
                $matches[1] = [int]$matches[1]
                if ($matches[1] -gt "10000")
                    {
                    $mark = 'Need cleaning'
                    Write-host $status["ServerName""-" $status["Results""========" $matches[1"***" $mark -foregroundcolor "DarkGreen"
                    }
                $status["Printer"] = $matches[1]
                $data += $status
                $OutArray += New-Object PsObject -Property @{'Date' = $status["TimeStamp"];'Result' = $status["Results"];'Printer' = $status["ServerName"];'Count' = $status["Printer"]}
                }
            $matches = ""
            $mark = ""
            }
        else
            {
            $status["Results"] = "Down"
            Write-host $status["ServerName""-" $status["Results""==========" $status["TimeStamp"-foregroundcolor "Yellow"
            $OutArray += New-Object PsObject -Property @{'Date' = $status["TimeStamp"];'Result' = $status["Results"];'Printer' = $status["ServerName"];'Count' = $status["Printer"]}
            }
}
$OutArray | Export-Csv $dir"\printers_report(full)$site.csv" -NoTypeInformation

pause 0

No comments:

Post a Comment