-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCCM_Bursar_Printer_Fix.ps1
95 lines (81 loc) · 2.31 KB
/
SCCM_Bursar_Printer_Fix.ps1
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
# --Script Summary--
# This scipt is basically what i run on each indivudual Bursar computer when they have printing issues(not as through though)
# This basically automates the removal and re adding of printer and driver on the user level - and wipes old printer share if present
# Something with the Bursar setup makes GPO half install the driver (unsure if print server or network issue)
# I can always tweak this or make another so you can assign printer name via script arguments for other uses
# !THIS HAS TO BE RAN UNDER THE LOGGED IN USER!
# -Author: Nate Faulds <[email protected]> | 7-12-2019
# Script Parameters
param([bool]$debug=0) # assign 1 for true to enable debug or leave blank for 0 to disable debug
# Variables
$oldPrinterShare = "FULL PRINTER NAME HERE"
$newPrinterShare = "FULL PRINTER NAME HERE"
# Functions
Function RemoveOld{
try {
$printerToDelete = Get-Printer -ErrorAction Stop -Name $oldPrinterShare
if($printerToDelete){ # Extra validation
if($debug){echo "Old printer present.....removing..."}
Remove-Printer -Name $oldPrinterShare
Sleep 2 # Sleeping just cause
if($debug){echo "Removed old printer!"}
}
}
catch {
if($debug){echo "Babe not found"}
}
}
Function PrinterPresent{
try{
Get-Printer -ErrorAction Stop -Name $newPrinterShare
return 1
}catch{
return 0
}
}
Function RemoveNew{
try{
Remove-Printer -Name $newPrinterShare
Sleep 2 # Sleeping just cause
}catch{
}
}
Function AddPrinter{
try{
Add-Printer -ConnectionName $newPrinterShare
Sleep 3 # Sleeping for driver install (yes it's veryyyy slow for some)
return 1
}catch{
return 0
}
}
Function ReturnFailure{
if($debug){echo "Failed adding printer!"}
# This includes the script exit handling and system exit handling
#[System.Environment]::Exit(1) # Return code for failure
Exit 1 # Script return code for failure
}
Function ReturnSuccess{
if($debug){echo "Printer added!"}
# This includes the script exit handling and system exit handling
#[System.Environment]::Exit(0) # Return code for success - GG
Exit 0 # Script return code for success - GG
}
# Script Invokes
RemoveOld # Just in case
if(PrinterPresent){
if($debug){echo "Removing printer found..."}
RemoveNew
if($debug){echo "Adding printer back..."}
if(AddPrinter){
ReturnSuccess
}else{
ReturnFailure
}
}else{
if(AddPrinter){
ReturnSuccess
}else{
ReturnFailure
}
}