Print Server Reporting Using Powershell

With very little work you can generate print reports like the one below. These reports can be styled using CSS. Additonally, these reports can be emailed or saved on the print server for archive. 

The script will generate a report that includes time, username, computer name, printer name, and number of pages printed. The script is looking specifically at 307 events inside of the print services operational logs. 


Example Report

TimeCreatedUserNameComputerNamePrinterNamePages
1/30/2020 3:36:35 PM countravioli ITLJRM192H ITLJ-RM192-P2050 5
1/30/2020 3:19:32 PM doctorpuerto-rico ITLJRM177A ITLJRM177-m451nw 1
1/30/2020 2:55:08 PM doctorpuerto-rico ITLJRM177A ITLJRM177-m425dn 1
1/30/2020 2:55:04 PM doctorpuerto-rico ITLJRM177A ITLJRM177-m425dn 13
1/30/2020 1:56:40 PM countravioli ITLJRM177B ITLJRM177-m425dn 2
1/30/2020 1:55:22 PM countravioli ITLJRM177B ITLJRM177-m425dn 1
1/30/2020 1:48:01 PM doctorpuerto-rico ITLJRM192A ITLJ-RM192-P2050 2
1/30/2020 1:40:06 PM countravioli ITLJRM108P ITLJRM108-m401n 5
1/30/2020 1:38:27 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:37:33 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:37:11 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:37:01 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:35:17 PM countravioli ITLJRM108R ITLJRM108-m401n 5
1/30/2020 1:34:06 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:33:50 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1
1/30/2020 1:33:27 PM gregorypopsicle ITLJRM254F ITLJRM254-m401n 1

 


Enabling Printer Logging

Operational logs for print services needs to be enabled.  To enable operational logging open Event Viewer and navigate to the following folder: Applications and Services Logs > Microsoft > Windows > PrintService . Inside of the PrintService folder, right click on Operational and select properties. 

Inside of the Operational properties check Enable Logging. I would suggest increasing the Maximum log size. On a production print server I recommend change it to 100032kb (approx. 100mb). Log size must be increased in increments of 64kb. 


 

General Settings

In the General Settings section, there are two variables that need values assigned. The $Organization_Name will be the name that is used inside of the generated report. The $Log_Files value specifies the location where the printer reports will be saved on the local computer. If the file path does not exist, the path wiill need to be created. 


#Name of Organization
$Organization_Name = ""

#Location of the Log Files. If the location does not exist, be sure to create a new folder. 
$Log_Files = "C:\Print-Logs"

 


SMTP Settings

The SMTP settings should be self explanitory. 


$SMTP_Username = ""
$SMTP_Password = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential ($SMTP_Username, $SMTP_Password)
$From = ""
$To = ""
$SMTPServer = ""
$SMTPPort = ""

 


 

CSS Styling

The reports can be styled using CSS. All CSS needs to be inside of the @ and " . See below example.


$css = @"

"@

 


Entire Script



###################################################
# ITLUMBERJACK.COM
# UPDATED ON: 1/30/20
# LICENSE: https://www.itlumberjack.com/mit-license
####################################################

########################
### General Settings ###
########################

#Name of Organization
$Organization_Name = ""

#Location of the Log Files. If the location does not exist, be sure to create a new folder. 
$Log_Files = "C:\Print-Logs"

#####################
### SMTP Settings ###
#####################

$SMTP_Username = ""
$SMTP_Password = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential ($SMTP_Username, $SMTP_Password)
$From = ""
$To = ""
$SMTPServer = ""
$SMTPPort = ""

###################
### CSS Styling ###
################### 

$css = @"

"@

###################################
####### Print Log Generator #######
### DO NOT EDIT BELOW THIS LINE ###
###################################

$Print_Log = Get-WinEvent -FilterHashTable @{LogName="Microsoft-Windows-PrintService/Operational"; ID=307; StartTime=(Get-Date).AddDays(-1)} |
Select-Object -Property TimeCreated,
                        @{label='UserName';expression={$_.properties[2].value}},
                        @{label='ComputerName';expression={$_.properties[3].value}},
                        @{label='PrinterName';expression={$_.properties[4].value}},
                        @{label='Pages';expression={$_.properties[7].value}} |
ConvertTo-Html -Head $css

$Print_Log | Out-File $Log_Files\$env:computername-PrintLog-$(get-date -f MM-dd-yyyy).html

$Subject = $Organization_Name + " : $env:computername Report | " + (Get-Date).ToString()
[email protected]"
$Print_Log
"@

Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Creds DeliveryNotificationOption OnSuccess -BodyAsHtml