Get name AND ip address of a printer

by deiandrei at 2013-04-04 07:12:23

Hi guys,

Got one problem, where I couldn’t find any answer so far:
I want to get the printer name and ip address (or hostaddress) of all printers on a printserver.
This is what I can do so far:

get-wmiobject win32_printer -computername Myprintserver | select deviceID,portname –> this will get me a list of all queues. But the win32_printer class does not get me the hostname of the printer. Yes, it does return the portname, but that does not help me very much. Portname and IP address can be different (and they often are).

get-wmiobject win32_tcpipprinterport -computername Myprintserver | select portname,hostaddress –> this will give me a list of all ports on the printserver. But I cannot filter the empty ports, which are not used by any printer. I might have 100 ports on the server, but only 30 used by printers.

So, there is no link between the queuename and the IP address, is there?
by ArtB0514 at 2013-04-04 07:28:11
So, why not collect all the portnames and make a hash table mapping the portnames to their ip addresses, and then, collect all the printers and lookup the ip address for the portname from the hash table?
by MasterOfTheHat at 2013-04-04 10:12:11
PortName in Win32_Printer should match up to Name in Win32_TCPIPPrinterPort. See if this gets you what you want:
gwmi win32_printer -ComputerName Server02 | %{ $printer = $.Name; $port = $.portname; gwmi win32_tcpipprinterport -computername jxps02 | where { $_.Name -eq $port } | select @{name="printername";expression={$printer}}, hostaddress }
by deiandrei at 2013-04-04 23:36:52
Thanks man! MasterOfTheHat, you really helped me out!
by MasterOfTheHat at 2013-04-05 07:06:09
Np. Glad it worked!