Public/Get-specInstalledIPPrinters.ps1
Function Get-specInstalledIPPrinters { <# .SYNOPSIS Retrieves a list of IP-based printers installed on the device. .DESCRIPTION The Get-specInstalledIPPrinters function checks all installed printers on the local device and filters out those that are IP-based. It evaluates the printer's port information to determine if the printer is connected via a TCP/IP port and has a valid IP address or hostname. .EXAMPLES # Example 1: Retrieve a list of all installed IP printers Get-specInstalledIPPrinters .RETURNS Returns an array of printers that are installed and configured to use TCP/IP ports. .NOTES Author: owen.heaume Version: 1.0 - Initial release #> [CmdletBinding()] Param () $installedIPPrinters = @() $allInstalledPrinters = Get-Printer foreach ($printer in $allInstalledPrinters) { # Get the printer port information $port = Get-PrinterPort -Name $printer.PortName # Check if the port is a TCP/IP port and has a valid IP address or hostname if ($port.PortMonitor -eq 'TCPMON.DLL' -and ($port.PrinterHostAddress -match '^\d{1,3}(\.\d{1,3}){3}$' -or $port.PrinterHostAddress)) { Write-Host "$($printer.name) is an IP printer" -ForegroundColor DarkGray $installedIPPrinters += $printer } } return $installedIPPrinters } |