Remote Printlog auslesen via Powershell / VB

  • PowerShell

    Remote Printlog auslesen via Powershell / VB

    Hallo Leute,
    hab bereits ein Tool, welches Printlogs mit dem Ereignis "307" auslesen kann und diese als CSV abspeichert.
    Leider fehlt mir in dem Log der Eintrag "Color", damit ich weiß ob schwarzweiß oder mit Farbe gedruckt worden ist.
    Ich schätze, dass es in der EventID 805 liegt. Leider habe ich keiner Ahnung, wie ich auf diese ID zugreifen kann?

    Das ist das Script, welches ich derzeit am laufen haben:

    Brainfuck-Quellcode

    1. <#
    2. .SYNOPSIS
    3. Print server job logs from Event Viewer to csv file
    4. .DESCRIPTION
    5. This script uses Get-WinEvent and XML queries to retrieve EventID 307 job logs from print servers.
    6. Specifically querying the Microsoft-Windows-PrintService/Operational log.
    7. Log is extracted to a CSV file and optionally emailed.
    8. .PARAMETER FileName
    9. <none>
    10. .EXAMPLE
    11. .\Print_ServerJobLogs.ps1
    12. .NOTES
    13. ScriptName: Print_ServerJobLogs.ps1
    14. Created By: TheAgreeableCow
    15. Date Coded: June 2012
    16. Requires Print Services Operational logging:
    17. Event Viewer > Applications and Service Logs > Microsoft > Windows > Print Service > Operational > Enable Log
    18. Remote severs may also need .NET 3.5 and Windows Remote Management configured (winrm -qc)
    19. Tested on Windows 2008R2
    20. .LINK
    21. http://theagreeablecow.blogspot.com.au/2012/06/using-get-winevent-and-xml-filters-to.html
    22. #>
    23. #LOAD VARIABLES
    24. #--------------
    25. Set-ExecutionPolicy unrestricted
    26. #Print Servers
    27. $ServerArray = @("MEINSERVER")
    28. $exchangeserver = "MEINEXCHANGE"
    29. $To = "MEINEEMAIL"
    30. $From = "MEINEBLABLABLA"
    31. #Output File
    32. $Date = (get-date) - (new-timespan -day 1)
    33. $OutputPath = "\\localhost\C$\temp\print\"
    34. $csvfile = $OutputPath + "Printing Audit - " + (Get-Date).ToString("yyyy-MM-dd") + ".csv"
    35. if ((Test-Path -Path $OutputPath+$csvfile) -eq $true) {remove-item $csvfile}
    36. write-output "Server,Date,Full Name,Client,Printer Name,Print Size,Pages,Document" | Out-File $csvfile
    37. #COLLECT EVENT LOGS FROM EACH PRINT SERVER
    38. #-----------------------------------------
    39. ForEach ($PrintServer in $ServerArray)
    40. {
    41. write-Host "Parsing event log entries for" $PrintServer
    42. $strOutput = ""
    43. #Apply query generated from Event Viewer > Filter Current Log > XML tab
    44. $filterxml = '<QueryList>
    45. <Query Id="0" Path="Microsoft-Windows-PrintService/Operational">
    46. <Select Path="Microsoft-Windows-PrintService/Operational">*[System[(EventID=307)]]</Select>
    47. </Query>
    48. </QueryList>'
    49. $EventLog = Get-WinEvent -ea SilentlyContinue -ComputerName $PrintServer -Filterxml $filterXml
    50. ForEach ($LogEntry in $EventLog)
    51. {
    52. #Get print job details
    53. $time = $LogEntry.TimeCreated
    54. $entry = [xml]$LogEntry.ToXml()
    55. $docName = $entry.Event.UserData.DocumentPrinted.Param2
    56. $Username = $entry.Event.UserData.DocumentPrinted.Param3
    57. $Computer = $entry.Event.UserData.DocumentPrinted.Param4
    58. $PrinterName = $entry.Event.UserData.DocumentPrinted.Param5
    59. $PrintSize = $entry.Event.UserData.DocumentPrinted.Param7
    60. $PrintPages = $entry.Event.UserData.DocumentPrinted.Param8
    61. #Get full name from AD
    62. if ($UserName -gt "")
    63. {
    64. $DirectorySearcher = New-Object System.DirectoryServices.DirectorySearcher
    65. $LdapFilter = "(&(objectClass=user)(samAccountName=${UserName}))"
    66. $DirectorySearcher.Filter = $LdapFilter
    67. $UserEntry = [adsi]"$($DirectorySearcher.FindOne().Path)"
    68. $DisplayName = $UserEntry.displayName
    69. }
    70. #$Write Log to CSV file
    71. $strOutput = $PrintServer+ "," +$time.ToString()+ "," +$DisplayName+ "," +$Computer+ "," +$PrinterName+ "," +$PrintSize+ "," +$PrintPages+ "," +$docName
    72. write-output $strOutput | Out-File $csvfile -append
    73. }
    74. }
    75. #REPORTING VIA EMAIL
    76. #-------------------
    77. #HTML style sheet
    78. $header = "<H3>Print Server Log Report "+(get-date -f D)+"</H3>"
    79. $title = "Example HTML Output"
    80. $body = '<style>
    81. BODY{font-family:Verdana; background-color:white;}
    82. TABLE{border-width: 1px;border-style:solid;border-color: black;border-collapse: collapse;}
    83. TH{font-size:1em; border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#C2B8AF}
    84. TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#F6F8FC}
    85. </style>
    86. '
    87. $EmailText = '<style>
    88. Log report Attached<BR>
    89. <BR>
    90. Regards,<BR>
    91. <BR>
    92. Admin Scripts<BR>
    93. '
    94. #Send email (with attached CSV)
    95. #$emailsubject = "[AUTO] Print Server Logs Report ("+(get-date -f dd-MM-yyyy)+")"
    96. #Send-MailMessage -To $To -From $From -Subject $emailsubject -SmtpServer $exchangeserver -body ($EmailText | Out-String) -BodyAsHtml -attachment $csvfile
    97. #ALternatively send email with data in email body
    98. #$emailbody = import-csv $csvfile | sort-object Server | ConvertTo-Html -head $header -body $body -title $title
    99. #Send-MailMessage -To $To -From $From -Subject $emailsubject -SmtpServer $exchangeserver -body ($emailbody, $EmailText | Out-String) -BodyAsHtml
    100. #remove-item $csvfile


    Bitte um Hilfe. :)