List printers and IP addresses on a windows server using powershell

From roonics
Revision as of 16:42, 3 March 2020 by Jlambert (talk | contribs) (Created page with "<pre> # Collect port names and host addresses into hash table $hostAddresses = @{} Get-WmiObject Win32_TCPIPPrinterPort | ForEach-Object { $hostAddresses.Add($_.Name, $_.Hos...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
# 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]
  }
}