153 lines
4.9 KiB
PowerShell
153 lines
4.9 KiB
PowerShell
# Printer Log Report 0.3
|
|
#
|
|
# Get-WinEvent on Englische Windows : Get-WinEvent -LogName "Microsoft-Windows-PrintService/Operational"
|
|
# Get-WinEvent on Deutsche Windows : Get-WinEvent -LogName "Microsoft-Windows-PrintService/Betriebsbereit"
|
|
|
|
|
|
$events = Get-WinEvent -LogName "Microsoft-Windows-PrintService/Operational" -MaxEvents 2000 |
|
|
Where-Object { $_.Id -eq 307 }
|
|
|
|
$logList = @()
|
|
|
|
foreach ($event in $events) {
|
|
$message = $event.Message
|
|
$user = ""
|
|
$computer = ""
|
|
$document = ""
|
|
$printer = ""
|
|
$pages = 0
|
|
|
|
if ($message -match "im Besitz von (.+?) wurde auf") {
|
|
$fullUser = $matches[1].Trim()
|
|
if ($fullUser -match "^(.+?) auf (.+)$") {
|
|
$user = $matches[1].Trim()
|
|
$computer = $matches[2].Trim()
|
|
} else {
|
|
$user = $fullUser
|
|
}
|
|
}
|
|
|
|
if ($message -match "wurde auf (.+?) über Port") {
|
|
$printer = $matches[1].Trim()
|
|
}
|
|
|
|
if ($message -match "Gedruckte Seiten:\s+(\d+)") {
|
|
$pages = [int]$matches[1]
|
|
}
|
|
|
|
if ($message -match "^Dokument\s+(\d+)") {
|
|
$document = "Dokument " + $matches[1]
|
|
}
|
|
|
|
$logList += [PSCustomObject]@{
|
|
Datum = $event.TimeCreated
|
|
Tag = $event.TimeCreated.Date.ToString("yyyy-MM-dd")
|
|
Woche = Get-Date $event.TimeCreated -UFormat "%Y-W%V"
|
|
Benutzer = $user
|
|
Computer = $computer
|
|
Dokument = $document
|
|
Drucker = $printer
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
|
|
# 🔹 Export részletes lista
|
|
$exportPfad = "$env:USERPROFILE\Desktop\drucklog_export.csv"
|
|
$logList | Export-Csv -Path $exportPfad -NoTypeInformation -Encoding UTF8
|
|
|
|
# 🔸 Összesítés felhasználónként (teljes)
|
|
$summary = $logList | Group-Object -Property Benutzer | ForEach-Object {
|
|
$userGroup = $_.Group
|
|
[PSCustomObject]@{
|
|
Benutzer = $_.Name
|
|
Anzahl_Dokumente = $userGroup.Count
|
|
Gesamt_Seiten = ($userGroup | Measure-Object -Property Seiten -Sum).Sum
|
|
}
|
|
}
|
|
$summary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_summary.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
# 🔸 Napi összesítés felhasználónként
|
|
$dailySummary = $logList | Group-Object -Property Tag, Benutzer | ForEach-Object {
|
|
$day = $_.Group[0].Tag
|
|
$user = $_.Group[0].Benutzer
|
|
$pages = ($_.Group | Measure-Object -Property Seiten -Sum).Sum
|
|
$docs = $_.Count
|
|
|
|
[PSCustomObject]@{
|
|
Datum = $day
|
|
Benutzer = $user
|
|
Dokumente = $docs
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
$dailySummary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_daily.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
# 🔸 Heti összesítés felhasználónként (ISO hét formátum: pl. 2025-W30)
|
|
$weeklySummary = $logList | Group-Object -Property Woche, Benutzer | ForEach-Object {
|
|
$week = $_.Group[0].Woche
|
|
$user = $_.Group[0].Benutzer
|
|
$pages = ($_.Group | Measure-Object -Property Seiten -Sum).Sum
|
|
$docs = $_.Count
|
|
|
|
[PSCustomObject]@{
|
|
Woche = $week
|
|
Benutzer = $user
|
|
Dokumente = $docs
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
$weeklySummary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_weekly.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
Write-Host "Exportálás kész:"
|
|
Write-Host "- Részletes lista: drucklog_export.csv"
|
|
Write-Host "- Összesítés: drucklog_summary.csv"
|
|
Write-Host "- Napi összesítés: drucklog_daily.csv"
|
|
Write-Host "- Heti összesítés: drucklog_weekly.csv"
|
|
|
|
# 🔸 Nyomtatónkénti összesítés
|
|
$printerSummary = $logList | Group-Object -Property Drucker | ForEach-Object {
|
|
$printer = $_.Name
|
|
$pages = ($_.Group | Measure-Object -Property Seiten -Sum).Sum
|
|
$docs = $_.Count
|
|
|
|
[PSCustomObject]@{
|
|
Drucker = $printer
|
|
Dokumente = $docs
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
|
|
$printerSummary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_by_printer.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
# 🔸 Napi összesítés nyomtatónként
|
|
$dailyPrinterSummary = $logList | Group-Object -Property Tag, Drucker | ForEach-Object {
|
|
$day = $_.Group[0].Tag
|
|
$printer = $_.Group[0].Drucker
|
|
$pages = ($_.Group | Measure-Object -Property Seiten -Sum).Sum
|
|
$docs = $_.Count
|
|
|
|
[PSCustomObject]@{
|
|
Datum = $day
|
|
Drucker = $printer
|
|
Dokumente = $docs
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
$dailyPrinterSummary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_daily_by_printer.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
# 🔸 Heti összesítés nyomtatónként
|
|
$weeklyPrinterSummary = $logList | Group-Object -Property Woche, Drucker | ForEach-Object {
|
|
$week = $_.Group[0].Woche
|
|
$printer = $_.Group[0].Drucker
|
|
$pages = ($_.Group | Measure-Object -Property Seiten -Sum).Sum
|
|
$docs = $_.Count
|
|
|
|
[PSCustomObject]@{
|
|
Woche = $week
|
|
Drucker = $printer
|
|
Dokumente = $docs
|
|
Seiten = $pages
|
|
}
|
|
}
|
|
$weeklyPrinterSummary | Export-Csv -Path "$env:USERPROFILE\Desktop\drucklog_weekly_by_printer.csv" -NoTypeInformation -Encoding UTF8
|