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

From roonics
Jump to navigation Jump to search
(Created page with "<pre> # Collect port names and host addresses into hash table $hostAddresses = @{} Get-WmiObject Win32_TCPIPPrinterPort | ForEach-Object { $hostAddresses.Add($_.Name, $_.Hos...")
(No difference)

Revision as of 16:42, 3 March 2020

# 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]
  }
}