1- <#
1+ <#
22. SYNOPSIS
33 Troubleshoots spooler, print queue, printers, drivers and related GPO policies.
44
@@ -30,7 +30,7 @@ if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory -Forc
3030$logPath = Join-Path $logDir " $scriptName .log"
3131
3232function Write-Log {
33- param ([string ]$Message , [ValidateSet (' INFO' , ' WARN' , ' ERROR' )]$Level = ' INFO' )
33+ param ([string ]$Message , [ValidateSet (' INFO' , ' WARN' , ' ERROR' )]$Level = ' INFO' )
3434 $ts = Get-Date - Format ' yyyy-MM-dd HH:mm:ss'
3535 Add-Content - Path $logPath - Value " [$ts ] [$Level ] $Message "
3636}
@@ -54,8 +54,8 @@ public class Win {
5454# ==== GUI BASE ====
5555Add-Type - AssemblyName System.Windows.Forms
5656Add-Type - AssemblyName System.Drawing
57- function Show-Info ($msg ) { [System.Windows.Forms.MessageBox ]::Show($msg , ' Information' , ' OK' , ' Information' ) | Out-Null }
58- function Show-Error ($msg ) { [System.Windows.Forms.MessageBox ]::Show($msg , ' Error' , ' OK' , ' Error' ) | Out-Null }
57+ function Show-Info ($msg ) { [System.Windows.Forms.MessageBox ]::Show($msg , ' Information' , ' OK' , ' Information' ) | Out-Null }
58+ function Show-Error ($msg ) { [System.Windows.Forms.MessageBox ]::Show($msg , ' Error' , ' OK' , ' Error' ) | Out-Null }
5959
6060# ==== SERVICES ====
6161function Stop-Spooler {
@@ -134,7 +134,7 @@ function Remove-AllPrinters {
134134 Write-Log " Trying to remove printer: $name "
135135
136136 if ($name -match " ^\\\\" ) {
137- rundll32 printui.dll, PrintUIEntry / dn / n " $name "
137+ rundll32 printui.dll, PrintUIEntry / dn / n " $name "
138138 Start-Sleep - Milliseconds 500
139139 }
140140
@@ -167,36 +167,36 @@ function Remove-PrinterDrivers-Interactive {
167167
168168 $form = New-Object Windows.Forms.Form
169169 $form.Text = " Remove Printer Drivers"
170- $form.Size = New-Object Drawing.Size(600 , 500 )
170+ $form.Size = New-Object Drawing.Size(600 , 500 )
171171 $form.StartPosition = ' CenterScreen'
172172
173173 $listBox = New-Object Windows.Forms.CheckedListBox
174174 $listBox.Location = ' 10,10'
175- $listBox.Size = New-Object Drawing.Size(560 , 380 )
175+ $listBox.Size = New-Object Drawing.Size(560 , 380 )
176176 foreach ($d in $drivers ) { [void ]$listBox.Items.Add ($d.Name ) }
177177 $form.Controls.Add ($listBox )
178178
179179 $btnRemove = New-Object Windows.Forms.Button
180180 $btnRemove.Text = " Remove Selected"
181- $btnRemove.Size = New-Object Drawing.Size(180 , 30 )
181+ $btnRemove.Size = New-Object Drawing.Size(180 , 30 )
182182 $btnRemove.Location = ' 10,410'
183183 $btnRemove.Add_Click ({
184- foreach ($item in $listBox.CheckedItems ) {
185- try {
186- Write-Log " Removing driver: ${item} "
187- Remove-PrinterDriver - Name " ${item} " - ErrorAction SilentlyContinue
188- } catch {
189- Write-Log " Error removing driver ${item} : $_ " " ERROR"
184+ foreach ($item in $listBox.CheckedItems ) {
185+ try {
186+ Write-Log " Removing driver: ${item} "
187+ Remove-PrinterDriver - Name " ${item} " - ErrorAction SilentlyContinue
188+ } catch {
189+ Write-Log " Error removing driver ${item} : $_ " " ERROR"
190+ }
190191 }
191- }
192- Show-Info " Driver removal completed."
193- $form.Close ()
194- })
192+ Show-Info " Driver removal completed."
193+ $form.Close ()
194+ })
195195 $form.Controls.Add ($btnRemove )
196196
197197 $btnCancel = New-Object Windows.Forms.Button
198198 $btnCancel.Text = " Cancel"
199- $btnCancel.Size = New-Object Drawing.Size(120 , 30 )
199+ $btnCancel.Size = New-Object Drawing.Size(120 , 30 )
200200 $btnCancel.Location = ' 420,410'
201201 $btnCancel.Add_Click ({ $form.Close () })
202202 $form.Controls.Add ($btnCancel )
@@ -234,36 +234,36 @@ $formMain.StartPosition = "CenterScreen"
234234
235235$btn1 = New-Object System.Windows.Forms.Button
236236$btn1.Text = " 1. Clear Print Queue"
237- $btn1.Location = New-Object System.Drawing.Point(20 , 40 )
238- $btn1.Size = New-Object System.Drawing.Size(540 , 40 )
237+ $btn1.Location = New-Object System.Drawing.Point(20 , 40 )
238+ $btn1.Size = New-Object System.Drawing.Size(540 , 40 )
239239$btn1.Add_Click ({ Clear-PrintQueue })
240240$formMain.Controls.Add ($btn1 )
241241
242242$btn2 = New-Object System.Windows.Forms.Button
243243$btn2.Text = " 2. Fix Spooler Dependency"
244- $btn2.Location = New-Object System.Drawing.Point(20 , 90 )
245- $btn2.Size = New-Object System.Drawing.Size(540 , 40 )
244+ $btn2.Location = New-Object System.Drawing.Point(20 , 90 )
245+ $btn2.Size = New-Object System.Drawing.Size(540 , 40 )
246246$btn2.Add_Click ({ Reset-SpoolerDependency })
247247$formMain.Controls.Add ($btn2 )
248248
249249$btn3 = New-Object System.Windows.Forms.Button
250250$btn3.Text = " 3. Remove All Printers"
251- $btn3.Location = New-Object System.Drawing.Point(20 , 140 )
252- $btn3.Size = New-Object System.Drawing.Size(540 , 40 )
251+ $btn3.Location = New-Object System.Drawing.Point(20 , 140 )
252+ $btn3.Size = New-Object System.Drawing.Size(540 , 40 )
253253$btn3.Add_Click ({ Remove-AllPrinters })
254254$formMain.Controls.Add ($btn3 )
255255
256256$btn4 = New-Object System.Windows.Forms.Button
257257$btn4.Text = " 4. Remove Selected Drivers"
258- $btn4.Location = New-Object System.Drawing.Point(20 , 190 )
259- $btn4.Size = New-Object System.Drawing.Size(540 , 40 )
258+ $btn4.Location = New-Object System.Drawing.Point(20 , 190 )
259+ $btn4.Size = New-Object System.Drawing.Size(540 , 40 )
260260$btn4.Add_Click ({ Remove-PrinterDrivers - Interactive })
261261$formMain.Controls.Add ($btn4 )
262262
263263$btn5 = New-Object System.Windows.Forms.Button
264264$btn5.Text = " 5. Reset Printer Policies (PointAndPrint)"
265- $btn5.Location = New-Object System.Drawing.Point(20 , 240 )
266- $btn5.Size = New-Object System.Drawing.Size(540 , 40 )
265+ $btn5.Location = New-Object System.Drawing.Point(20 , 240 )
266+ $btn5.Size = New-Object System.Drawing.Size(540 , 40 )
267267$btn5.Add_Click ({ Reset-PrinterPolicies })
268268$formMain.Controls.Add ($btn5 )
269269
0 commit comments