This PowerShell script will continuously prints the current time and pings an IP address.
It will run in a loop until you press Ctrl+C
to stop it.
# Replace <IP> with target host IP address
try {
while ($true) {
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$pingResult = ping <IP> -n 1
if ($pingResult -match "Reply from") {
Write-Host "$timestamp - Host is up"
} else {
Write-Host "$timestamp - Host is down"
}
Start-Sleep -Seconds 1
}
} catch {
Write-Host "Script interrupted."
}