-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-GlobalPrinters.ps1
More file actions
49 lines (43 loc) · 1.56 KB
/
Get-GlobalPrinters.ps1
File metadata and controls
49 lines (43 loc) · 1.56 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
function Get-GlobalPrinters {
<#
.SYNOPSIS
Get globally installed printers from a remote computer
.DESCRIPTION
Get globally installed printers from a remote computer
.EXAMPLE
PS C:\> Get-GlobalPrinters -ComputerName 999TSTPC999
Gets printer information
.INPUTS
[string] for ComputerName
.OUTPUTS
[PSCustomObject] as results
.NOTES
Requires remote registry permissions
#>
[CmdletBinding()]
param (
# Name of computer to retrieve information from
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string]$ComputerName
)
if (!(Test-Connection -Count 1 -ComputerName $ComputerName -Quiet))
{
throw "Unable to connect to $ComputerName"
}
try{
# Open remote registry
$RemoteRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName)
# Set Global installed printers path
$GlobalInstalledPrintersPath = 'Software\Microsoft\Windows NT\CurrentVersion\Print\Connections\'
# Open global printer installed path
$GlobalKey = $RemoteRegistry.OpenSubKey($GlobalInstalledPrintersPath)
# Get the connection names for each printer
$GlobalInstalledPrinters = $GlobalKey.GetSubKeyNames() | ForEach-Object { $GlobalKey.OpenSubKey($_).GetValue('Printer').ToUpper() }
}
catch{
throw $_
}
return $GlobalInstalledPrinters
}