Skriptgesteuerte Drucker-Installation

26. Juni 2018

Aus Sicherheitsgründen sollten die Systembetreuer immer genau im Bilde sein, welche IT-Ressourcen von welchen Mitarbeitern in Anspruch genommen wurden. Beispielsweise können die Systembetreuer in Erfahrung bringen wollen, wann welcher User auf einen bestimmten Printer zugegriffen hat. Für derartige Aufgabenstellungen eignet sich die Windows Powershell, denn mit den passenden Skripten und Cmdlets lässt sich dies einfach und schnell realisieren:

1function Get-PrinterServerUsers {
2 <#
3  .SYNOPSIS
4  List all users that have printed from specified printerservers the last xxx days.
5  .DESCRIPTION
6  The function creates a list of all users that have used specified printerservers.
7  To be able to collect the events you need to log spooler information events.
8  .PARAMETER Computername
9  A single computer name or an array of computer names. You may also provide IP addresses.
10  .PARAMETER days
11  The number of days from todays date you whant to list.
12  .EXAMPLE
13  Get-PrinterServerUsers -computername srv-print01, srv-print02 -days 90
14  
15  Description
16  ———–
17  This will collect all the users that have prited from a printer through the servers
18  srv-print01 and srv-print02 the last 90 days, and export them to a textfile with the
19  servername located at c:\temp.
20  .LINK
21  Powerhell.nu
22  .NOTES
23  Function by Viktor Lindström
24  v1.0 – 12/19/2014
25  #>
26  
27param(
28[parameter(mandatory=$true)]
29[array]
30$Computername,
31  
32[parameter()]
33[int]
34$days
35)   
36  
37$date = get-date
38$tempdir = "c:\temp"
39  
40#Check if directory c:\temp exist, and if not create it.
41if ( -Not (Test-Path $tempdir))
42 { New-Item -Path $tempdir -ItemType Directory
43 }
44  
45  
46foreach ($server in $computername)
47{Write-Host collecting users from $server
48$Duration = Measure-Command {
49$users = get-eventlog -ComputerName $server -LogName  system  -After $date.AddDays(-$days) | where {$_.eventID -eq 10} | select UserName
50$unique = $users | Sort-Object username | Get-Unique -AsString
51$unique | Export-Csv c:\temp\$server.txt -NoTypeInformation }
52Write-host "$($Server) done in $($Duration.Minutes):$($Duration.Seconds) mm:ss"
53    }
54    }

Florian Huttenloher

Lesen Sie auch