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
 
(2 intermediate revisions by the same user not shown)
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 10: Line 12:
     "Name" = $_.Name
     "Name" = $_.Name
     "DriverName" = $_.DriverName
     "DriverName" = $_.DriverName
    "Status" = $_.Status
     "HostAddress" = $hostAddresses[$_.PortName]
     "HostAddress" = $hostAddresses[$_.PortName]
   
   }
   }
}
}
Line 25: Line 29:
Microsoft Print To PDF                  Microsoft Print to PDF
Microsoft Print To PDF                  Microsoft Print to PDF
</pre>
</pre>
[[Category:PowerShell]]
‎<comments />

Latest revision as of 10:04, 20 March 2022

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
    "Status" = $_.Status
    "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

‎<comments />