Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notmayo/212735c96fb0e573d26e1713ac658915 to your computer and use it in GitHub Desktop.
Save notmayo/212735c96fb0e573d26e1713ac658915 to your computer and use it in GitHub Desktop.
Ping status script that does not require a separate txt file.
set-executionpolicy unrestricted
clear
while($true)
{
$date = Get-Date
$sleep = 10
$Tab = [char]9
Write-Host -Fore "Blue" "Ping status $date"
Write-Output -----
$PingCommercial = "8.8.8.8"
ForEach($MachineName In $PingCommercial)
{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
Select-Object StatusCode
If ($PingStatus.StatusCode -eq 0)
{Write-Host Commercial: $($tab)$($tab) $MachineName $($tab)$($tab) Connection successful -Fore "Green"}
Else
{Write-Host Commercial: $($tab)$($tab) $MachineName $($tab)$($tab) Connection failure -Fore "Red"}}
$PingNIPR = "www.my.af.mil"
ForEach($MachineName In $PingNIPR)
{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
Select-Object StatusCode
If ($PingStatus.StatusCode -eq 0)
{Write-Host NIPR: $($tab) $($tab)$($tab) $MachineName $($tab)$($tab) Connection successful -Fore "Green"}
Else
{Write-Host NIPR: $($tab) $($tab)$($tab) $MachineName $($tab)$($tab) Connection failure -Fore "Red"}}
$PingNMS = "172.30.14.6"
ForEach($MachineName In $PingNMS)
{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |
Select-Object StatusCode
If ($PingStatus.StatusCode -eq 0)
{Write-Host SATCOM NMS: $($tab)$($tab) $MachineName $($tab)$($tab) Connection successful -Fore "Green"}
Else
{Write-Host SATCOM NMS: $($tab)$($tab) $MachineName $($tab)$($tab) Connection failure -Fore "Red"}}
Write-Output -----
Write-Host -Fore "White" "Waiting $($sleep) second(s)"
Write-Output " "
start-sleep -seconds $sleep
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment