Public/Printing/Test-PrinterPort.ps1
<#
Copyright © 2024 Integris. For internal company use only. All rights reserved. #> FUNCTION Test-PrinterPort { <# .SYNOPSIS Tests the network port connectivity for a specified IP address. .DESCRIPTION This function tests the network connectivity of port 9100 for a specified IP address. It performs a TCP connection test and returns the result. If the port is open, it displays a success message. If the port is closed or an error occurs, it displays an appropriate message. .PARAMETER IPAddress Specifies the IP address of the printer to test the port connectivity. .EXAMPLE Test-PrinterPort -IPAddress "192.168.1.100" Tests the network connectivity of port 9100 for the printer with the IP address "192.168.1.100". .INPUTS System.String. The function accepts a string input for the printer's IP address. .OUTPUTS System.String. Returns "Success" if the port is open, "Failure" if closed, and "ERROR" if an error occurs. .NOTES Ensure you have the necessary permissions to perform network tests. #> param ( [string]$IPAddress ) try { $tcpConnection = Test-NetConnection -ComputerName $IPAddress -Port 9100 -InformationLevel Detailed if ($tcpConnection.TcpTestSucceeded) { Write-Host "Port 9100 on '$IPAddress' is open." -ForegroundColor Green RETURN "Success" } else { Write-Host "Port 9100 on '$IPAddress' is closed." -ForegroundColor Red RETURN "Failure" } } catch { Write-Host "Failed to test port 9100 on '$IPAddress'. Error: $_" -ForegroundColor Red RETURN "ERROR" } } |