Drucker per PowerShell auf Printserver installieren
Hallo Kolleginnen und Kollegen,
vor kurzem gab es schon einmal eine Frage zur installation von Druckern auf Printservern, allerdings sollte in diesem Fall ein Skript direkt auf dem Printserver laufen und dort Drucker installieren.
Ich hätte es gerne, dass ich von meinem Client aus per Powershell auf verschiedenen Printservern Druckerobjekte mit entsprechendem Port installieren kann, ohne jedes mal eine RDP-Sitzung zum Drucker zu starten.
Ich habe auch schon ein bisschen rum gebastelt, mein Skript läuft auch ohne Fehler durch (PowerShell ISE).
Wenn es eine Möglichkeit gibt die Textdateien zu umgehen, also alles nur durch das Skript laufen zu lassen und zum Schluss eine Logdatei zu schreiben, welche den Printserver, den Druckernamen, die IP-Adresse, den Standort und das Druckermodell enthält, wäre ich auch hierüber sehr dankbar.
und nun mein Skript:
vor kurzem gab es schon einmal eine Frage zur installation von Druckern auf Printservern, allerdings sollte in diesem Fall ein Skript direkt auf dem Printserver laufen und dort Drucker installieren.
Ich hätte es gerne, dass ich von meinem Client aus per Powershell auf verschiedenen Printservern Druckerobjekte mit entsprechendem Port installieren kann, ohne jedes mal eine RDP-Sitzung zum Drucker zu starten.
Ich habe auch schon ein bisschen rum gebastelt, mein Skript läuft auch ohne Fehler durch (PowerShell ISE).
Wenn es eine Möglichkeit gibt die Textdateien zu umgehen, also alles nur durch das Skript laufen zu lassen und zum Schluss eine Logdatei zu schreiben, welche den Printserver, den Druckernamen, die IP-Adresse, den Standort und das Druckermodell enthält, wäre ich auch hierüber sehr dankbar.
und nun mein Skript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#printer add script
#Created from Scripting guys example scripts and Stephen Small.
#
#Löscht alle variablen, damit bei einem doppelten Lauf keine Werte vergeben sind.
$portname = ""
$IPaddress = ""
$driver = ""
$location = ""
$comment = ""
$printserver = ""
#Erstellen der Form
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Printer Add"
$objForm.Size = New-Object System.Drawing.Size(300,550)
$objForm.StartPosition = "CenterScreen"
# Erstellen der Label für die Texteingabe (Druckername)
$objLabel1 = New-Object System.Windows.Forms.Label
$objLabel1.Location = New-Object System.Drawing.Size(10,20)
$objLabel1.Size = New-Object System.Drawing.Size(280,20)
$objLabel1.Text = "Druckername:"
$objForm.Controls.Add($objLabel1)
$objTextBox1 = New-Object System.Windows.Forms.TextBox
$objTextBox1.Location = New-Object System.Drawing.Size(10,40)
$objTextBox1.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox1)
# Erstellen der Label für die Texteingabe (IP-Adresse)
$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,70)
$objLabel2.Size = New-Object System.Drawing.Size(280,20)
$objLabel2.Text = "IP-Adresse:"
$objForm.Controls.Add($objLabel2)
$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,90)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)
# Erstellen der Label für die Texteingabe (Standort)
$objLabel3 = New-Object System.Windows.Forms.Label
$objLabel3.Location = New-Object System.Drawing.Size(10,120)
$objLabel3.Size = New-Object System.Drawing.Size(280,20)
$objLabel3.Text = "In welchem Zimmer steht der Drucker?"
$objForm.Controls.Add($objLabel3)
$objTextBox3 = New-Object System.Windows.Forms.TextBox
$objTextBox3.Location = New-Object System.Drawing.Size(10,150)
$objTextBox3.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox3)
# Erstellen der Label für die Texteingabe (Printserver)
$objLabel4 = New-Object System.Windows.Forms.Label
$objLabel4.Location = New-Object System.Drawing.Size(10,180)
$objLabel4.Size = New-Object System.Drawing.Size(280,20)
$objLabel4.Text = "Printserver Name:"
$objForm.Controls.Add($objLabel4)
$objTextBox4 = New-Object System.Windows.Forms.TextBox
$objTextBox4.Location = New-Object System.Drawing.Size(10,200)
$objTextBox4.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox4)
# Erstellen der Label für die Texteingabe (Kommentar)
$objLabel5 = New-Object System.Windows.Forms.Label
$objLabel5.Location = New-Object System.Drawing.Size(10,230)
$objLabel5.Size = New-Object System.Drawing.Size(280,20)
$objLabel5.Text = "Comment:"
$objForm.Controls.Add($objLabel5)
$objTextBox5 = New-Object System.Windows.Forms.TextBox
$objTextBox5.Location = New-Object System.Drawing.Size(10,250)
$objTextBox5.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox5)
# Liste der Drucker, die eingerichtet werden Können (Pfad zur *.ini muss noch eingerichtet werden)
$objLabel6 = New-Object System.Windows.Forms.Label
$objLabel6.Location = New-Object System.Drawing.Size(10,280)
$objLabel6.Size = New-Object System.Drawing.Size(280,20)
$objLabel6.Text = "Suchen Sie den Druckertreiber aus:"
$objForm.Controls.Add($objLabel6)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,300)
$objListBox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Height = 160
$objListbox.SelectionMode = "one"
[void] $objListBox.Items.Add("HP Color LaserJet 3505")
[void] $objListBox.Items.Add("HP Color LaserJet 3800")
[void] $objListBox.Items.Add("HP LaserJet 1320")
[void] $objListBox.Items.Add("Lexmark C510")
[void] $objListBox.Items.Add("Lexmark MS510dn")
[void] $objListBox.Items.Add("Lexmark C734dn")
[void] $objListBox.Items.Add("Lexmark C746")
[void] $objListBox.Items.Add("Lexmark E120n")
[void] $objListBox.Items.Add("Lexmark E352dn")
[void] $objListBox.Items.Add("Lexmark E360dn")
[void] $objListBox.Items.Add("Lexmark E460dn")
[void] $objListBox.Items.Add("Lexmark T420")
[void] $objListBox.Items.Add("Lexmark T650")
[void] $objListBox.Items.Add("Lexmark X544")
[void] $objListBox.Items.Add("Kyocera Mita FS-1010")
[void] $objListBox.Items.Add("Kyocera Mita FS-6020")
[void] $objListBox.Items.Add("NRG 1805d 1808d 1802d")
[void] $objListBox.Items.Add("NRG 1305 1308 1302")
[void] $objListBox.Items.Add("NRG 2205 2238 2212")
[void] $objListBox.Items.Add("NRG 3545 3518 3532")
[void] $objListBox.Items.Add("NRG 6002 6005 6008")
[void] $objListBox.Items.Add("NRG 7502 7505 7508")
[void] $objListBox.Items.Add("NRG DSm 415")
[void] $objListBox.Items.Add("NRG DSm 615")
[void] $objListBox.Items.Add("NRG DSm 618")
[void] $objListBox.Items.Add("NRG DSm 622")
[void] $objListBox.Items.Add("NRG DSm 651")
[void] $objListBox.Items.Add("NRG DSm 735")
[void] $objListBox.Items.Add("NRG MP 2550")
[void] $objListBox.Items.Add("NRG P 7325N")
[void] $objListBox.Items.Add("Ricoh Aficio 3025")
[void] $objListBox.Items.Add("Ricoh Aficio 3045")
[void] $objListBox.Items.Add("Ricoh Aficio MP 5000B")
[void] $objListBox.Items.Add("Ricoh Aficio MP 5500")
[void] $objListBox.Items.Add("Ricoh Aficio MP 6000")
[void] $objListBox.Items.Add("Ricoh Aficio MP 7500")
$objListBox.SelectedItem
$objForm.Controls.Add($objListBox)
# HIER STEHEN JETZT DIE BUTTONS!!!
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$driver=$objListBox.SelectedItem;$portname=$objTextBox1.Text;$IPaddress=$objTextBox2.Text;$Location=$objTextBox3.Text;$printserver=$objTextbox4.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$Cancel=$True;$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,480)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$driver=$objListBox.SelectedItem;$portname=$objTextBox1.Text;$IPaddress=$objTextBox2.Text;$Location=$objTextBox3.Text;$comment=$objTextBox5.Text;$printserver=$objTextbox4.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,480)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$Cancel=$True;$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
if ($Cancel -eq $True)
{Exit}
#Hinzufügen der Daten zu den Textdateien für die spätere Erstellung der Objekte
Clear-Content c:\printeraddscript\ports.txt
add-content c:\printeraddscript\ports.txt "Printserver,Portname,IPAddress"
add-content c:\printeraddscript\ports.txt "$printservername","$portname","$IPaddress"
Clear-Content c:\printeraddscript\printers.txt
add-content c:\printeraddscript\printers.txt "Printserver,Driver,PortName,ShareName,Location,Comment,DeviceID"
add-content c:\printeraddscript\printers.txt "$printservername","$driver","$portname","$portname","$location","$IPaddress", "$driver","$portname"
#Erstellt das Druckerobjekt mit Hilfe der Textdokumente
function CreatePrinterPort {
$server = $args
$port = ([WMICLASS]"\\$printserver\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name = $args[1]
$port.SNMPEnabled = $true
$port.SNMPCommunity = ""
$port.Protocol = 1
$port.Portnumber = "9100"
$port.HostAddress = $args[2]
}
function CreatePrinter{
$server = $args
$print = ([WMICLASS]"\\$printserver\ROOT\cimv2:Win32_Printer").createInstance()
$print.Drivername = $args[1]
$print.PortName = $args[2]
$print.Shared = $true
$print.Published = $true
$print.Sharename = $args[3]
$print.Location = $args[4]
$print.Comment = $args[5]
$print.DeviceID = $args[6]
}
#Log File
$printers = Import-Csv c:\printeraddscript\printers.txt
$ports = Import-Csv c:\printeraddscript\ports.txt
$filename = "printeradd-{0:d2}-{1:d2}-{2:d2}.log" -f $date.month,$date.day,$date.year
$filepath = "c:\printeraddscript\"
foreach ($port in $ports){
CreatePrinterPort $port.Printserver $port.Portname $port.IPAddress
}
foreach ($printer in $printers){
CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.DeviceID
$date = Get-Date; Add-Content -Path $filepath\$filename ("Printer $($portname) was added on $($printserver) at $($date)")
}
#Balloon tip on Cmplettion
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Icon = "C:\ProgramData\Microsoft\Device Stage\Task\{e35be42d-f742-4d96-a50a-1775fb1a7a42}\print_queue.ico"
$objNotifyIcon.BalloonTipIcon = "Info"
$objNotifyIcon.BalloonTipText = ("Der Drucker" , $portname , " wurde auf dem Server" , $printserver , "hinzugefügt.")
$objNotifyIcon.BalloonTipTitle = "Printer add Complete"
$objNotifyIcon.Visible = $False
$objNotifyIcon.ShowBalloonTip(20000)
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 256361
Url: https://administrator.de/forum/drucker-per-powershell-auf-printserver-installieren-256361.html
Ausgedruckt am: 12.04.2025 um 05:04 Uhr
19 Kommentare
Neuester Kommentar
Hallo pago,
etwa so (ungetestet mangels zur Verfügung stehender Drucker):
Grüße Uwe
etwa so (ungetestet mangels zur Verfügung stehender Drucker):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$txtPrinterPort = New-Object System.Windows.Forms.NumericUpDown
$label7 = New-Object System.Windows.Forms.Label
$comboPrintServer = New-Object System.Windows.Forms.ComboBox
$btnCancel = New-Object System.Windows.Forms.Button
$btnOK = New-Object System.Windows.Forms.Button
$label6 = New-Object System.Windows.Forms.Label
$txtPrinterComment = New-Object System.Windows.Forms.TextBox
$txtPrinterLocation = New-Object System.Windows.Forms.TextBox
$label4 = New-Object System.Windows.Forms.Label
$lbPrinterType = New-Object System.Windows.Forms.ListBox
$txtPrinterIP = New-Object System.Windows.Forms.TextBox
$txtPrintername = New-Object System.Windows.Forms.TextBox
$label3 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
$label1 = New-Object System.Windows.Forms.Label
$label5 = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
# Event Script Blocks
#----------------------------------------------
$createPrinter = {
Try{
$printserver = $comboPrintServer.Text
$portname = "IP_$($txtPrinterIP.Text)"
# create printer port
$wmi = ([WMICLASS]"\\$printserver\ROOT\cimv2:Win32_TCPIPPrinterPort")
$wmi.psbase.scope.options.enablePrivileges = $true
$port = $wmi.CreateInstance()
$port.Name = $portname
$port.Protocol = 1
$port.Portnumber = $txtPrinterPort.Text
$port.HostAddress = $txtPrinterIP.Text
$port.SNMPEnabled = $False
$port.put()
#create printer instance
$print = ([WMICLASS]"\\$printserver\ROOT\cimv2:Win32_Printer").createInstance()
$print.Drivername = $lbPrinterType.SelectedItem
$print.PortName = $portname
$print.Shared = $true
$print.Published = $true
$print.Sharename = $txtPrintername.Text
$print.Location = $txtPrinterLocation.Text
$print.Comment = $txtPrinterComment.Text
$print.DeviceID = $txtPrintername.Text
$print.put()
return $true
}catch{
return $_.Exception.Message
}
}
$handler_btnOK_Click = {
# Drucker erstellen
$result = &$createPrinter
# wenn erfolgreich ...
$logtext = ""
if ($result -eq $true){
$logtext = @"
-------- $(get-date -Format "g") ---------- Drucker auf Printserver '$($comboPrintServer.Text)' hinzugefügt: --------------
Druckername: $($txtPrintername.Text)
IP-Adresse: $($txtPrinterIP.Text)
Port: $($txtPrinterPort.Value)
Treiber: $($lbPrinterType.SelectedItem)
Standort: $($txtPrinterLocation.Text)
Kommentar: $($txtPrinterComment.Text)
$("-"*20)
"@
[System.Windows.Forms.MessageBox]::Show("Der Drucker $txtPrintername wurde auf dem Printserver $($comboPrintServer.Text) angelegt.")
}else{
$logtext = @"
-------- $(get-date -Format "g") ---------- !!! ACHTUNG FEHLER !! beim hinzufügen des Druckers auf Printserver '$($comboPrintServer.Text)': --------------
Druckername: $($txtPrintername.Text)
IP-Adresse: $($txtPrinterIP.Text)
Port: $($txtPrinterPort.Value)
Treiber: $($lbPrinterType.SelectedItem)
Standort: $($txtPrinterLocation.Text)
Kommentar: $($txtPrinterComment.Text)
$("-"*20)
"@
[System.Windows.Forms.MessageBox]::Show("Beim Anlegen des Druckers/Ports ist ein Fehler aufgetreten: $result")
}
Add-Content "logfile.log" $logtext -Force
}
$handler_btnCancel_Click = {
$form1.Close()
}
$handler_form1_Load = {
# add printer drivers to List
$lbPrinterType.Items.AddRange(@(
"HP Color LaserJet 3505",
"HP Color LaserJet 3800",
"HP LaserJet 1320",
"Lexmark C510",
"Lexmark MS510dn",
"Lexmark C734dn",
"Lexmark C746",
"Lexmark E120n",
"Lexmark E352dn",
"Lexmark E360dn",
"Lexmark E460dn",
"Lexmark T420",
"Lexmark T650",
"Lexmark X544",
"Kyocera Mita FS-1010",
"Kyocera Mita FS-6020",
"NRG 1805d 1808d 1802d",
"NRG 1305 1308 1302",
"NRG 2205 2238 2212",
"NRG 3545 3518 3532",
"NRG 6002 6005 6008",
"NRG 7502 7505 7508",
"NRG DSm 415",
"NRG DSm 615",
"NRG DSm 618",
"NRG DSm 622",
"NRG DSm 651",
"NRG DSm 735",
"NRG MP 2550",
"NRG P 7325N",
"Ricoh Aficio 3025",
"Ricoh Aficio 3045",
"Ricoh Aficio MP 5000B",
"Ricoh Aficio MP 5500",
"Ricoh Aficio MP 6000",
"Ricoh Aficio MP 7500"
))
# add printservers
$comboPrintServer.Items.AddRange(@(
".",
"SERVER01",
"SERVER02",
"SERVER03",
"SERVER04"
))
$comboPrintServer.SelectedIndex = 0
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 472
$System_Drawing_Size.Width = 274
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 500
$System_Drawing_Size.Width = 282
$form1.MinimumSize = $System_Drawing_Size
$form1.Name = "form1"
$form1.Text = "Create Printer"
$form1.add_Load($handler_form1_Load)
$txtPrinterPort.Anchor = 9
$txtPrinterPort.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 186
$System_Drawing_Point.Y = 75
$txtPrinterPort.Location = $System_Drawing_Point
$txtPrinterPort.Maximum = 65536
$txtPrinterPort.Minimum = 1
$txtPrinterPort.Name = "txtPrinterPort"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 76
$txtPrinterPort.Size = $System_Drawing_Size
$txtPrinterPort.TabIndex = 2
$txtPrinterPort.TextAlign = 2
$txtPrinterPort.Value = 9100
$form1.Controls.Add($txtPrinterPort)
$label7.Anchor = 9
$label7.DataBindings.DefaultDataSourceUpdateMode = 0
$label7.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 186
$System_Drawing_Point.Y = 58
$label7.Location = $System_Drawing_Point
$label7.Name = "label7"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 59
$label7.Size = $System_Drawing_Size
$label7.TabIndex = 11
$label7.Text = "Port"
$form1.Controls.Add($label7)
$comboPrintServer.Anchor = 14
$comboPrintServer.DataBindings.DefaultDataSourceUpdateMode = 0
$comboPrintServer.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 391
$comboPrintServer.Location = $System_Drawing_Point
$comboPrintServer.Name = "comboPrintServer"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 249
$comboPrintServer.Size = $System_Drawing_Size
$comboPrintServer.TabIndex = 6
$form1.Controls.Add($comboPrintServer)
$btnCancel.Anchor = 10
$btnCancel.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 186
$System_Drawing_Point.Y = 437
$btnCancel.Location = $System_Drawing_Point
$btnCancel.Name = "btnCancel"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$btnCancel.Size = $System_Drawing_Size
$btnCancel.TabIndex = 8
$btnCancel.Text = "Abbrechen"
$btnCancel.UseVisualStyleBackColor = $True
$btnCancel.add_Click($handler_btnCancel_Click)
$form1.Controls.Add($btnCancel)
$btnOK.Anchor = 10
$btnOK.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 105
$System_Drawing_Point.Y = 437
$btnOK.Location = $System_Drawing_Point
$btnOK.Name = "btnOK"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$btnOK.Size = $System_Drawing_Size
$btnOK.TabIndex = 7
$btnOK.Text = "OK"
$btnOK.UseVisualStyleBackColor = $True
$btnOK.add_Click($handler_btnOK_Click)
$form1.Controls.Add($btnOK)
$label6.Anchor = 6
$label6.DataBindings.DefaultDataSourceUpdateMode = 0
$label6.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 368
$label6.Location = $System_Drawing_Point
$label6.Name = "label6"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 250
$label6.Size = $System_Drawing_Size
$label6.TabIndex = 10
$label6.Text = "Erstellen auf folgendem PrintServer"
$form1.Controls.Add($label6)
$txtPrinterComment.Anchor = 14
$txtPrinterComment.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 339
$txtPrinterComment.Location = $System_Drawing_Point
$txtPrinterComment.Name = "txtPrinterComment"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 250
$txtPrinterComment.Size = $System_Drawing_Size
$txtPrinterComment.TabIndex = 5
$form1.Controls.Add($txtPrinterComment)
$txtPrinterLocation.Anchor = 14
$txtPrinterLocation.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 294
$txtPrinterLocation.Location = $System_Drawing_Point
$txtPrinterLocation.Name = "txtPrinterLocation"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 251
$txtPrinterLocation.Size = $System_Drawing_Size
$txtPrinterLocation.TabIndex = 4
$form1.Controls.Add($txtPrinterLocation)
$label4.Anchor = 6
$label4.DataBindings.DefaultDataSourceUpdateMode = 0
$label4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 275
$label4.Location = $System_Drawing_Point
$label4.Name = "label4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 169
$label4.Size = $System_Drawing_Size
$label4.TabIndex = 6
$label4.Text = "Standort"
$form1.Controls.Add($label4)
$lbPrinterType.Anchor = 15
$lbPrinterType.DataBindings.DefaultDataSourceUpdateMode = 0
$lbPrinterType.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 133
$lbPrinterType.Location = $System_Drawing_Point
$lbPrinterType.Name = "lbPrinterType"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 121
$System_Drawing_Size.Width = 250
$lbPrinterType.Size = $System_Drawing_Size
$lbPrinterType.TabIndex = 3
$form1.Controls.Add($lbPrinterType)
$txtPrinterIP.Anchor = 13
$txtPrinterIP.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 75
$txtPrinterIP.Location = $System_Drawing_Point
$txtPrinterIP.Name = "txtPrinterIP"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 168
$txtPrinterIP.Size = $System_Drawing_Size
$txtPrinterIP.TabIndex = 1
$form1.Controls.Add($txtPrinterIP)
$txtPrintername.Anchor = 13
$txtPrintername.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 26
$txtPrintername.Location = $System_Drawing_Point
$txtPrintername.Name = "txtPrintername"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 250
$txtPrintername.Size = $System_Drawing_Size
$txtPrintername.TabIndex = 0
$form1.Controls.Add($txtPrintername)
$label3.DataBindings.DefaultDataSourceUpdateMode = 0
$label3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 107
$label3.Location = $System_Drawing_Point
$label3.Name = "label3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label3.Size = $System_Drawing_Size
$label3.TabIndex = 2
$label3.Text = "Druckertyp"
$form1.Controls.Add($label3)
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 58
$label2.Location = $System_Drawing_Point
$label2.Name = "label2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label2.Size = $System_Drawing_Size
$label2.TabIndex = 1
$label2.Text = "IP-Adresse"
$form1.Controls.Add($label2)
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 9
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 0
$label1.Text = "Druckername"
$form1.Controls.Add($label1)
$label5.Anchor = 6
$label5.DataBindings.DefaultDataSourceUpdateMode = 0
$label5.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 11
$System_Drawing_Point.Y = 321
$label5.Location = $System_Drawing_Point
$label5.Name = "label5"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 169
$label5.Size = $System_Drawing_Size
$label5.TabIndex = 9
$label5.Text = "Kommentar"
$form1.Controls.Add($label5)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
Servus ihr zwei,
das ist ja eine tolle Weiterentwicklung
Ich erhalte beispielsweise auf dem Printserver folgende Meldung. Die Drucker werden erstellt.
Auf dem PS habe ich PS 2.0 und auf meinem Laptop 3.0
Benötige ich eine andere Version dafür?
das ist ja eine tolle Weiterentwicklung
Ich erhalte beispielsweise auf dem Printserver folgende Meldung. Die Drucker werden erstellt.
Auf dem PS habe ich PS 2.0 und auf meinem Laptop 3.0
Benötige ich eine andere Version dafür?
1
2
3
4
5
6
7
2
3
4
5
6
7
Der Typ [System.Windows.MessageBox] kann nicht gefunden werden: Stellen Sie sicher, dass die Assembly, die diesen Typ e
nthält, geladen wird.
Bei C:\Users\*****\Desktop\Drucker_GUIps1:85 Zeichen:36
+ [System.Windows.MessageBox] <<<< ::Show("Der Drucker $txtPrintername wurde auf dem Printserver $($comboPrintS
erver.Text) angelegt.")
+ CategoryInfo : InvalidOperation: (System.Windows.MessageBox:String) , RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Korrekt. Nu klappts.
Habe sogar remote einen Drucker auf dem Printserver anlegen können.
Das ist ein Tool das hier einen Admins sicherlich gefallen wird :o)
So hab ich mir das gedanklich vorgestellt. War ja froh das dass Skript aus dem Technet zum laufen gebracht wurde.
Das ist jetzt die SUPER Version von diesem Ding. :o)
Habe sogar remote einen Drucker auf dem Printserver anlegen können.
Das ist ein Tool das hier einen Admins sicherlich gefallen wird :o)
So hab ich mir das gedanklich vorgestellt. War ja froh das dass Skript aus dem Technet zum laufen gebracht wurde.
Das ist jetzt die SUPER Version von diesem Ding. :o)
Zitat von @Pago159:
Leider läuft das Script bei mir in den ErrorHandler mit folgender Meldung:
Beim Anlegen des Druckers/Ports ist ein Fehler aufgetreten:
\\printserver\ROOT\cimv2:Win32_TCPIPPrinterPort.Name="IP_IP-Adresse"
Ausnahme beim Aufruf von "Put" mit 0 Argument(en): "Allgemeiner Fehler"
Kann es sein, dass das Script für ein x64 System andere Klassen benutzt um den Port zu erstellen?
Nein, sehr wahrscheinlich hast du den Druckertreiber auf dem Printserver noch nicht installiert. Dieser Fall ließe sich ebenfalls noch mit einbinden:Leider läuft das Script bei mir in den ErrorHandler mit folgender Meldung:
Beim Anlegen des Druckers/Ports ist ein Fehler aufgetreten:
\\printserver\ROOT\cimv2:Win32_TCPIPPrinterPort.Name="IP_IP-Adresse"
Ausnahme beim Aufruf von "Put" mit 0 Argument(en): "Allgemeiner Fehler"
Kann es sein, dass das Script für ein x64 System andere Klassen benutzt um den Port zu erstellen?
http://www.adminarsenal.com/admin-arsenal-blog/how-to-add-printers-with ...
Lass ich dir mal als Hausaufgabe
Grüße Uwe
Zitat von @Pago159:
Auf Server2 liefert die Abfrage "Get-WmiObject Win32_Printer" allerdings die Fehlermeldung, dass die WMI KLasse nicht gefunden werden kann.
Dann hat's auf diesem Server sehr wahrscheinlich das WMI Repository zerschossen, oder eine der benötigten DLLs ist nicht mehr richtig registriert.Auf Server2 liefert die Abfrage "Get-WmiObject Win32_Printer" allerdings die Fehlermeldung, dass die WMI KLasse nicht gefunden werden kann.
Hier findest du ein Script um das zu fixen:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/68310b21 ...
Grüße Uwe
Zitat von @Pago159:
kann es sein, dass dieses Code-Schnipsel die Win32_Printer Klasse löscht, anstatt dem Druckerobjekt?
Hallo Pago,kann es sein, dass dieses Code-Schnipsel die Win32_Printer Klasse löscht, anstatt dem Druckerobjekt?
das wäre mit absolut neu, kann ich hier auch testweise nicht bestätigen. Da stimmt an deinem Script irgendwas nicht.
gwmi Win32_TCPIPPrinterPort -computer $printserver -Filter "HostAddress = '$name'" | %{$_.Delete()}
Ausnahme beim Aufruf von "Delete" mit 0 Argument8en): "Allgemeiner Fehler"
das ist genau der Fehler wenn der Port noch nicht gelöscht werden kann weil er noch in Verwendung ist, dann musst du eventuell eine kleine Pause zwischen den Vorgängen einbauensleep 1
und nutze meine Zeile von oben, dann kommt kein Fehler wenn der Port schon nicht mehr existiert:
gwmi Win32_TCPIPPrinterPort -computer $printserver -Filter "HostAddress = '$name'" | %{$_.Delete()}
p.s. können wir den Thread jetzt bitte schließen, das eigentliche Thema ist ja erledigt.