Public/Printing/Test-PrinterPing.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Test-PrinterPing {
    <#
    .SYNOPSIS
    Tests the network reachability of a printer via ping.
 
    .DESCRIPTION
    This function tests the network reachability of a printer using its IP address. It performs a ping test and returns the result. If the printer is reachable, it displays a success message. If the printer is not reachable or an error occurs, it displays an appropriate message.
 
    .PARAMETER IPAddress
    Specifies the IP address of the printer to be pinged.
 
    .EXAMPLE
    Test-PrinterPing -IPAddress "192.168.1.100"
    Tests the network reachability of 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 printer is reachable, "Failure" if not, and "ERROR" if an error occurs.
 
    .NOTES
    Ensure you have the necessary permissions to perform network tests.
    #>


    param (
        [string]$IPAddress
    )

    try {
        $pingResult = Test-Connection -ComputerName $ipAddress -Count 1 -ErrorAction SilentlyContinue
        if ($pingResult) {
            Write-Host "Printer '$($printer.Name)' is reachable via ping." -ForegroundColor Green
            RETURN "Success"
        } else {
            Write-Host "Printer '$($printer.Name)' is not reachable via ping." -ForegroundColor Red
            RETURN "Failure"
        }
    } catch {
        Write-Host "Failed to ping test '$IPAddress'. Error: $_" -ForegroundColor Red
        RETURN "ERROR"
    }
}