Private/Helper/Start-PSPingCheck.ps1
<#
Copyright © 2024 Integris. For internal company use only. All rights reserved. #> FUNCTION Start-PSPingCheck { <# .SYNOPSIS Checks if a specified address is reachable by pinging it multiple times. .DESCRIPTION This function sends ICMP echo requests to a specified address multiple times and returns true if any of the pings are successful. .PARAMETER Address The address to ping. .PARAMETER Count The number of echo requests to send. Default is 3. .PARAMETER Delay The delay in seconds between each echo request. Default is 2 seconds. .EXAMPLE Start-PSPingCheck -Address "8.8.8.8" -Count 5 -Delay 1 .NOTES The function uses Test-Connection to perform the ping and returns true if any ping is successful. #> PARAM ( [Parameter(Mandatory)] $Address, $Count = 3, $Delay = 2 ) FOR ($I = 1; $I -le $Count; $I++) { $Test = Test-Connection $Address -Count 1 -Delay $Delay -ErrorAction SilentlyContinue IF ($null -eq $Test.Status) { IF ($Test.StatusCode -eq 0) { RETURN $True } } } RETURN $False } |