76 lines
2.3 KiB
PowerShell
76 lines
2.3 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 500 |
|
|
Where-Object { $_.Id -eq 307 }
|
|
|
|
$logList = @()
|
|
|
|
foreach ($event in $events) {
|
|
$message = $event.Message
|
|
$user = ""
|
|
$computer = ""
|
|
$document = ""
|
|
$printer = ""
|
|
$pages = 0
|
|
|
|
# Felhasználó és gép különválasztása
|
|
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
|
|
}
|
|
}
|
|
|
|
# Nyomtató neve (pl. Jasenitz)
|
|
if ($message -match "wurde auf (.+?) über Port") {
|
|
$printer = $matches[1].Trim()
|
|
}
|
|
|
|
# Oldalszám (pl. Gedruckte Seiten: 1)
|
|
if ($message -match "Gedruckte Seiten:\s+(\d+)") {
|
|
$pages = [int]$matches[1]
|
|
}
|
|
|
|
# Dokument sorszám (pl. Dokument 62)
|
|
if ($message -match "^Dokument\s+(\d+)") {
|
|
$document = "Dokument " + $matches[1]
|
|
}
|
|
|
|
$logList += [PSCustomObject]@{
|
|
Datum = $event.TimeCreated
|
|
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
|
|
$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
|
|
}
|
|
}
|
|
|
|
# Export összesítés
|
|
$summaryPfad = "$env:USERPROFILE\Desktop\drucklog_summary.csv"
|
|
$summary | Export-Csv -Path $summaryPfad -NoTypeInformation -Encoding UTF8
|
|
|
|
Write-Host "Exportálás kész:"
|
|
Write-Host "- Részletes lista: $exportPfad"
|
|
Write-Host "- Felhasználónkénti összesítés: $summaryPfad"
|