Files
WPanda/Scripts/powershell/Drucker_Überwachung_0.1.ps1
2025-12-15 10:00:38 +01:00

48 lines
1.2 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$events = Get-WinEvent -LogName "Microsoft-Windows-PrintService/Operational" -MaxEvents 500 |
Where-Object { $_.Id -eq 307 }
$logList = @()
foreach ($event in $events) {
$message = $event.Message
$user = ""
$document = ""
$printer = ""
$pages = ""
# Felhasználó (pl. L.Vogt auf APS-NB072)
if ($message -match "im Besitz von (.+?) wurde auf") {
$user = $matches[1].Trim()
}
# 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]
}
# Dokumentum sorszám (pl. Dokument 62) jobb híján
if ($message -match "^Dokument\s+(\d+)") {
$document = "Dokument " + $matches[1]
}
$logList += [PSCustomObject]@{
Datum = $event.TimeCreated
Benutzer = $user
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"