How to create powershell script for Audit Printer Event logs?

Home Forums Server Operating Systems Windows Server 2008 / 2008 R2 How to create powershell script for Audit Printer Event logs?

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    qamrul2001
    Member
    #162631

    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:WindowsSystem32winevtLogs -recurse |

    ForEach-Object {

    “Parsing $($_.fullname)rn”

    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,

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.