Write-Host "collecting event logs..." $Date = (get-date) - (new-timespan -day 1) $PrintEntries = Get-WinEvent -ea SilentlyContinue -ComputerName SERVERNAME -FilterHashTable @{ProviderName="Microsoft-Windows-PrintService"; StartTime=$Date; ID=307} $strOutput = "" $File = "Printing Audit - " + (Get-Date).ToString("yyyy-MM-dd") + ".csv" write-output "Date|Username|Full Name|Client|Printer Name|Print Size|Pages|Document" | Out-File $File write-Host "Parsing event log entries..." ForEach ($PrintEntry in $PrintEntries) { #Get date and time of printjob from TimeCreated $Date_Time = $PrintEntry.TimeCreated $entry = [xml]$PrintEntry.ToXml() $docName = $entry.Event.UserData.DocumentPrinted.Param2 $Username = $entry.Event.UserData.DocumentPrinted.Param3 $Client = $entry.Event.UserData.DocumentPrinted.Param4 $PrinterName = $entry.Event.UserData.DocumentPrinted.Param5 $PrintSize = $entry.Event.UserData.DocumentPrinted.Param7 $PrintPages = $entry.Event.UserData.DocumentPrinted.Param8 #Get full name from AD if ($UserName -gt "") { $DirectorySearcher = New-Object System.DirectoryServices.DirectorySearcher $LdapFilter = "(&(objectClass=user)(samAccountName=${UserName}))" $DirectorySearcher.Filter = $LdapFilter $UserEntry = [adsi]"$($DirectorySearcher.FindOne().Path)" $ADName = $UserEntry.displayName } #$rawMessage $strOutput = $Date_Time.ToString()+ "|" +$UserName+ "|" +$ADName+ "|" +$Client+ "|" +$PrinterName+ "|" +$PrintSize+ "|" +$PrintPages+ "|" +$docName write-output $strOutput | Out-File $File -append }