#ScriptName: SendingInterestingTraffic.ps1
#Purpose: To Send interesting traffic inside the VPN tunnel

$names = '10.220.23.100','100.64.1.100','10.123.64.100','10.20.21.11','10.20.22.11'            # Seclore PolicyServer
$servers = @()                          # collection of servers and their status
foreach ($name in $names){              # populate the initial collection  
    $servers +=     [PSCustomObject]@{
        SeclorePolicyServer = $name
        Online       = $null 
    }
}
"{0} SendingInterestingTraffic Starting" -f (get-date)                                  # write to the screen if interactive
while ($true) {                                                             # run forever, assume that we have been launched at system startup
    foreach ($server in $servers) {
        $ping = Test-NetConnection -ComputerName $server.SeclorePolicyServer   -ErrorAction SilentlyContinue
        if (($ping.pingsucceeded -eq $true) -and ($server.online -eq $true)) {
            # No need to do anything, the server is up and it was up during the last execution.
            # Uncomment the next statement to write this event to the log file.
            # "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer 
            "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer         
        }
        elseif (($ping.pingsucceeded -eq $false)  -and ($server.online -eq $false)) {
            # During our last check, the server did not ping, but now it does.
            # Log the event and change the status.
            #"{0} {1} sending interesting traffic failed." -f (get-date), $server.SeclorePolicyServer  
            "{0} {1} sending interesting traffic failed." -f (get-date), $server.SeclorePolicyServer  
        }
        elseif (($ping.pingsucceeded -eq $true) -and ($server.online -eq $false)) {
            # During our last check, the server did not ping, but now it does.
            # Log the event and change the status.
            "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer 
            "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer  
            $server.online = $true                        # update our status 
        }
        elseif ($ping.pingsucceeded -eq $true) {
            $server.online = $true
            "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer 
            "{0} {1} sending interesting traffic." -f (get-date), $server.SeclorePolicyServer  
            $server.online = $true                       # update our status 
        }
        elseif ($ping.pingsucceeded -eq $false) {
            "{0} {1} sending interesting traffic failed." -f (get-date), $server.SeclorePolicyServer
            "{0} {1} sending interesting traffic failed" -f (get-date), $server.SeclorePolicyServer  
            $server.online = $false                      # update our status 
        }
        else {
            "{0} Testing {1}, but something is wrong. We should not get to this statement. " -f (get-date), $server.SeclorePolicyServer
            "{0} Testing {1}, but something is wrong. We should not get to this statement. " -f (get-date), $server.SeclorePolicyServer 
        }  
    } 
    start-sleep -Seconds 30 
}