Announcement

Collapse
No announcement yet.

How to create powershell script for Audit Printer Event logs?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create powershell script for Audit Printer Event logs?

    Dear all,

    We have used below PowerShell script in our winsvr2008 r2 print server for Audit Printer Event Logs created by B. Bickett and collected from below link:
    after that our required logs didnít fulfill. we want to log with below info from event viewer:

    Print job owner name, date and time, computer name, print job doc name, printer name, print count log per user, control print job to individual user etc. can any help me how i edit script and put to PowerShell.

    $dte = Get-Date

    $m = $dte.month

    $cmonth = Get-Date -UFormat %m

    $d = $dte.day

    $cday = Get-Date -UFormat %d

    $cyear = $dte.year

    $filename = "ColorPrinterLog_" + $cyear + "_" +$cmonth + ".csv"

    $startdatefull = ($dte).AddDays(-30)

    $startdate = ($startdatefull).ToShortDateString()

    $enddate = ($dte).ToShortDateString()

    "Job Name: Monthly Color Printer Log"

    "Start Date: " + $startdate

    "End Date: " + $enddate

    Write-Host " " | Out-File "C:\$filename"

    Write-Host "Scanning Archived Printer Event Logs..."

    Write-Host

    Get-ChildItem -include Archive-Microsoft-Windows-PrintService%4Operational-$cyear-$cmonth*.evtx -Path C:\Windows\System32\winevt\Logs -recurse |

    ForEach-Object {

    "Parsing $($_.fullname)`r`n"

    Try

    { $events = get-winevent -FilterHashTable @{Path=$_.fullname; ID=307; StartTime=$startdate; EndTime=$enddate ;} |

    where {($_.Message -like "*printer1*") -or ($_.Message -like "*printer2*") -or ($_.Message -like "*printer3*") -or ($_.Message -like "*printer4*") -or ($_.Message -like "*printer5*") -or ($_.Message -like "*printer6*") } |

    select timecreated,message |

    Export-Csv "C:\Temp.csv" -Encoding ASCII -notype

    [System.IO.File]::ReadAllText("C:\Temp.csv") | Out-File -Append "C:\$filename"

    }

    Catch [System.Exception] {"No results in current log"}

    }

    Write-Host

    Write-Host "Scanning Complete!"

    Write-Host

    Thanks,
Working...
X