55 lines
1.4 KiB
PowerShell
55 lines
1.4 KiB
PowerShell
$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 = ""
|
|
|
|
# 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 = $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álás CSV-be
|
|
$exportPfad = "$env:USERPROFILE\Desktop\drucklog_export.csv"
|
|
$logList | Export-Csv -Path $exportPfad -NoTypeInformation -Encoding UTF8
|
|
|
|
Write-Host "Exportálás kész: $exportPfad"
|