List printers and IP addresses on a windows server using powershell: Difference between revisions

From roonics
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
The below will list all printers on the server and its IP address:
<pre>
<pre>
# Collect port names and host addresses into hash table
# Collect port names and host addresses into hash table
Line 25: Line 27:
Microsoft Print To PDF                  Microsoft Print to PDF
Microsoft Print To PDF                  Microsoft Print to PDF
</pre>
</pre>
[[Category:PowerShell]]

Revision as of 16:44, 3 March 2020

The below will list all printers on the server and its IP address:

# Collect port names and host addresses into hash table
$hostAddresses = @{}
Get-WmiObject Win32_TCPIPPrinterPort | ForEach-Object {
  $hostAddresses.Add($_.Name, $_.HostAddress)
}

Get-WmiObject Win32_Printer | ForEach-Object {
  New-Object PSObject -Property @{
    "Name" = $_.Name
    "DriverName" = $_.DriverName
    "HostAddress" = $hostAddresses[$_.PortName]
  }
}

Example output:

DriverName                               Name                          HostAddress
----------                               ----                          -----------
Xerox WorkCentre 7855                    Printer01                     10.10.10.10
Xerox WorkCentre 7220                    Printer02                     10.10.10.20
HP Color LaserJet CP202X PS Class Driver Printer03                     10.10.10.30
Microsoft XPS Document Writer v4         Microsoft XPS Document Writer
Microsoft Print To PDF                   Microsoft Print to PDF