$ sudo crontab -u www-data -e
35 2 * * 7 /usr/bin/php /var/www/personal/utils/import-print-logs.php > /dev/null 2>&1
Date;Username;Full Name;Client;Printer Name;Port;Print Size;Pages;Document;SrvComp
Расшифровка:
Дата;Логин;Полное имя пользователя;Имя компьютера;Имя принтера;Порт;Размер в байтах;Кол-во страниц;Название документа;Имя сервера
Write-Host "collecting event logs..."
$Date = (get-date) - (new-timespan -day 1)
$PrintEntries = Get-WinEvent -ea SilentlyContinue -ComputerName localhost -FilterHashTable @{ProviderName="Microsoft-Windows-PrintService"; StartTime=$Date; ID=307}
$strOutput = ""
$File = "\\172.30.1.70\PrintLogs\Printing AuditS91" + (Get-Date).ToString("yyyy-MM-dd") + ".csv"
write-output "Date;Username;Full Name;Client;Printer Name;Port;Print Size;Pages;Document;SrvComp" | Out-File $File -Encoding UTF8
write-Host "Parsing event log entries..."
ForEach ($PrintEntry in $PrintEntries)
{
продолжение ⇓
#Get date and time of printjob from TimeCreated
$Date_Time = $PrintEntry.TimeCreated
#$SrvComp = $PrintEntry.Computer
$entry = [xml]$PrintEntry.ToXml()
$SrvComp = $entry.Event.System.Computer
$docName = $entry.Event.UserData.DocumentPrinted.Param2
$Username = $entry.Event.UserData.DocumentPrinted.Param3
$Client = $entry.Event.UserData.DocumentPrinted.Param4
$PrinterName = $entry.Event.UserData.DocumentPrinted.Param5
$Port = $entry.Event.UserData.DocumentPrinted.Param6
$PrintSize = $entry.Event.UserData.DocumentPrinted.Param7
$PrintPages = $entry.Event.UserData.DocumentPrinted.Param8
#Get full name from AD
if ($UserName -gt "")
{
$DirectorySearcher = New-Object System.DirectoryServices.DirectorySearcher
$LdapFilter = "(&(objectClass=user)(samAccountName=${UserName}))"
$DirectorySearcher.Filter = $LdapFilter
$UserEntry = [adsi]"$($DirectorySearcher.FindOne().Path)"
$ADName = $UserEntry.displayName
}
#$rawMessage
$strOutput = $Date_Time.ToString("yyyy-MM-dd HH:mm:ss")+";" +$UserName+ ";" +$ADName+ ";" +$Client+ ";" +$PrinterName+ ";" +$Port+ ";" +$PrintSize+ ";" +$PrintPages+ ";" +$docName+ ";" +$SrvComp
write-output $strOutput | Out-File $File -append -Encoding UTF8
}
write-Host "Operation complete."
Dim oNet
Dim sPrintServer
On Error Resume Next
' default print server
sPrintserver = "s91"
продолжение ⇓
' Удаляем сущестующие принтеры
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\" & sPrintServer & "\test pached P5018", true, true
WshNetwork.RemovePrinterConnection "\\" & sPrintServer & "\test pached P5018v2", true, true
WshNetwork.RemovePrinterConnection "\\" & sPrintServer & "\Ricoh Aficio 9Б", true, true
WshNetwork.RemovePrinterConnection "\\" & sPrintServer & "\Ricoh Aficio 7Б", true, true
WshNetwork.RemovePrinterConnection "\\" & sPrintServer & "\Ricoh Aficio 6Б", true, true
' Добавляем принтер в зависимости от группы
Set oNet = CreateObject("WScript.Network")
If IsMember("AcceptPrint") then
oNet.AddWindowsPrinterConnection "\\" & sPrintServer & "\Test pached P5018"
oNet.SetDefaultPrinter "\\" & sPrintServer & "\Test pached P5018"
End If
If IsMember("DeclinePrint") then
oNet.AddWindowsPrinterConnection "\\" & sPrintServer & "\Test pached P5018v2"
oNet.SetDefaultPrinter "\\" & sPrintServer & "\Test pached P5018v2"
End If
If IsMember("Printer3") then
oNet.AddWindowsPrinterConnection "\\" & sPrintServer & "\Printer3"
oNet.SetDefaultPrinter "\\" & sPrintServer & "\Printer3"
End If
If IsMember("Printer4") then
oNet.AddWindowsPrinterConnection "\\" & sPrintServer & "\Printer4"
oNet.SetDefaultPrinter "\\" & sPrintServer & "\Printer4"
End If
' FUNCTION ============ IsMEmber ======================================
Function IsMember(sGroup)
' IsMember
' Test to see if user if member of specified group
продолжение ⇓
' sGroup Name of group
' Returns True if user is group member
Dim sAdsPath, oUser, oGroup
' ================= Populate dictionary if not yet created =======================
If IsEmpty(g_oGroupDict) Then
Set g_oGroupDict = CreateObject("Scripting.Dictionary")
g_oGroupDict.CompareMode = vbTextCompare
sAdsPath = oNet.UserDomain & "/" & oNet.UserName
On Error Resume Next
Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
If Err.Number then
IsMember = FALSE
Exit Function
End IF
On Error Goto 0
For Each oGroup In oUser.Groups
g_oGroupDict.Add oGroup.Name, "-"
Next
Set oUser = Nothing
End If
IsMember = CBool(g_oGroupDict.Exists(sGroup))
End Function
Полезная функция, которую не видно
Через поиск, расположенный в верхнем меню, можно найти задания печати за определённую дату и при этом содержащие определённое (большее или равное) количество листов.
То есть, предположим нам нужно найти все задания печати за 28 августа 2011 года с кол-вом отпечатанных листов больше 100. Строка поиска при этом должна быть равна следующему
2011-08-28,100 и переключатель поиска должен быть установлен на отметку Дата