-
Notifications
You must be signed in to change notification settings - Fork 1
/
JV_PrinterScript.ps1
80 lines (59 loc) · 2.94 KB
/
JV_PrinterScript.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
#Created by Ryan Curran
# 3/21/24
#######################
Add-type -AssemblyName PresentationCore, PresentationFramework
#Variables
#---------------------Static Values---------------------------
#Dont change these values
$githost = "github.com"
$gitpath = "https://github.com/TurnerJVDriverRepo/TCCODrivers/raw/main/"
$tcpipPort = "9100"
$userpath = "$env:userprofile\Downloads\"
#---------------------End Static Values-----------------------
#Printer IP Address
$printerIP = "192.168.252.240"
#The name the end user will see for their printer entry
$printerDisplayname = "Princeton - Ricoh C6004"
#DriverName can be found inside of the "INF" file for the driver
$driverName = "RICOH MP C4500 PCL 6"
#Get the name of the ZIP from github (Example: Ricoh_C8003.zip)
$driverZipName = "Ricoh C4500.zip"
#Build the URL
$driverZipLink = $driverZipName -replace ' ', '%20'
$driverURL = $gitpath+$driverZipLink
$tc = test-connection $githost -Count 1 -Quiet
if ($tc -eq $True){
"Connection Test Success"
}else{
[System.windows.messagebox]::show("Connection test failed, please make sure you are connected to the internet")
exit
}
#Window Title
$host.UI.RawUI.WindowTitle = "Installing Printer $PrinterDisplayName"
Write-Host "Installing $printerDisplayName Printer, Please Wait......`n" -ForegroundColor Green
Write-Host "[=======25 ]`n" -ForegroundColor Green
Write-host "Downloading the printer driver from the external repo (Github)`n" -ForegroundColor Green
#CURL Driver from Github
Invoke-WebRequest -Uri $driverURL -Outfile $env:userprofile\Downloads\Driver.zip
Write-Host "[===========65 ]`n" -ForegroundColor Green
Write-Host "Extracting the Printer Driver`n"
$dirtest = Get-Childitem $userpath | select Name
if ($Dirtest.name -contains "Driver"){
"Driver folder detected in $userpath, renaming to driver.bak"
mv $userpath\driver $userpath\driver.bak
"Expanding driver archive"
Expand-Archive -Path $userpath\Driver.zip $userpath\Driver -Force
}else{
"No Driver folder detected in $userpath, expanding driver archive"
Expand-Archive -Path $userpath\Driver.zip $userpath\Driver -Force
}
Write-Host "`n[================75 ]`n" -ForegroundColor Green
Write-Host "Creating the Printer port`n" -ForegroundColor Green
#Creating Printer TCPIP Port
CSCRIPT /nologo $env:windir\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "$printerIP" -o raw -n 9100 -h "$printerIP"
Write-Host "Printer port created with IP $printerIP`n" -ForegroundColor Green
Write-Host "`n[=====================90 ]`n" -ForegroundColor Green
Write-Host "Creating Printer Entry $printerDisplayName`n" -ForegroundColor Green
rundll32 printui.dll,PrintUIEntry /if /n "$PrinterDisplayName" /b "$PrinterDisplayName" /f "$userpath\Driver\Ricoh C6004\oemsetup.inf " /r "$printerIP" /m "$driverName"
Write-Host "`n[==========================100]`n" -ForegroundColor Green
[System.windows.messagebox]::show("Printer $PrinterDisplayName is now Installed")