-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsPrintModule.ps1
More file actions
111 lines (87 loc) · 2.37 KB
/
WindowsPrintModule.ps1
File metadata and controls
111 lines (87 loc) · 2.37 KB
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
# This module is written by Robert Sinrud (http://whenindoubtbacon.wordpress.com/)
# It is freely available
#
#
#
#remove specific printer driver
function Remove-PrintDriver {
param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true,Position=0)]
$driverName
)
Set-Location c:\windows\system32\printing_admin_scripts\en-us
$cmd = "cscript prndrvr.vbs -d -m " + '"' + $drivername + '"' + " -v 3 -e" + ' "' + "Windows x64" + '"'
Invoke-Expression $cmd
}
#Collecting locally installed drivers
function Get-PrintDriver {
param(
[String]$Name
)
$localDrivers = @()
foreach ($driver in (Get-WmiObject Win32_PrinterDriver)){
$localDrivers += @(($driver.name -split ",")[0])
}
if(!$Name){
return $localDrivers
}else{
$value = $localDrivers | Where-Object {$_ -like "*$name*"}
return $value
}
}
#remove all unused print drivers
function Remove-UnusedPrintDrivers {
param(
)
Set-Location c:\windows\system32\printing_admin_scripts\en-us
Invoke-Expression "cscript prndrvr.vbs -x"
}
#delete printer
function Remove-Printer {
param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true,Position=0)]
$printerName,
[Parameter(ValueFromPipeline=$false,Mandatory=$false,Position=1)]
[Switch]$removeDriver = $true
)
#/dd Deletes a printer driver.
#/dn Deletes a network printer connection.
#/n Name of the printer
# if($removeDriver){$driver = "/dd"}
$cmd = "rundll32 printui.dll,PrintUIEntry /dn /n""$printerName"""
Invoke-Expression $cmd
}
#enumerate installed network printers
function Get-Printer {
<#
.SYNOPSIS
Get-Printer lists all printers installed.
.DESCRIPTION
This function calls the Win32_Printer WMI object and pulls all installed printers. The default value returned is the Device ID.
.PARAMETER ParameterA
-Network $true
The network parameter sets wether you want network printers or all printers
.EXAMPLE
Get-Printer -Network $true
.EXAMPLE
Get-Printer
.INPUTS
System.String,System.Int32
.OUTPUTS
System.String
#>
param(
[String]$Name,
[Switch]$Network
)
if($Network){
$cmd = "Get-WmiObject Win32_Printer -EnableAllPrivileges -Filter network=true"
}else{$cmd = "Get-WmiObject Win32_Printer -EnableAllPrivileges"}
[array] $printers = invoke-expression $cmd
if(!$name){
return $printers
}else{
$result = $printers | Where-Object {$_.DeviceID -like "*$Name*"}
return $result
}
}