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
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
     "Name" = $_.Name
     "Name" = $_.Name
     "DriverName" = $_.DriverName
     "DriverName" = $_.DriverName
    "Status" = $_.Status
     "HostAddress" = $hostAddresses[$_.PortName]
     "HostAddress" = $hostAddresses[$_.PortName]
   
   }
   }
}
}
Line 29: Line 31:


[[Category:PowerShell]]
[[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 />