Search code examples
powershellethernetinvoke-command

Invoke-Command blocks connection on secondary Network


I have 2 computers. One is a data server which is connected to the internet. This data server pushes a TimeSync script every hour to the other computers which are not connected to the internet. So basically, they are all connected by Ethernet but only the Data Server knows the current time based on online data. The second computer is Computer B.

So here's the problem.

Computer B has 2 network cards. One to communicate with the Data Server and one to communicate with a PLC (Programmable Logic Controller). And whenever the TimeSync script runs, the communication between Computer B and the PLC (Network card #2) is interfered for the duration of the script, providing no errors into Windows Registry.

Network 1 (A) : 200.200.200.X Network B (PLC) : 150.150.150.X

I've checked on multiple websites, I found literally nothing.

$pingtimeout = 5
$buffersize = 16


#Filter for ping response, allowing to pass ping parameters, unavailale through Test-Connection (Ping Timeout for example)
filter Invoke-FastPing {(New-Object System.Net.NetworkInformation.Ping).send($_,$pingtimeout,$buffersize)}

#Sweeping the network
foreach($num in 1..254)
{

    if("200.200.200.$num" | invoke-fastping | Where-Object status -eq 'success')
    {
        #Set time for each computer
        $time = get-date
        $output = Invoke-Command 200.200.200.$num {set-date $using:time} -ArgumentList $time
        if ($output -ne $null)
        {
            Start-Process -WindowStyle hidden -FilePath PowerShell.exe -Verb Runas -ArgumentList "Write-EventLog -LogName System -Source 'Timesync Script' -EntryType Information -EventId 1 -Message 'Time update on 200.200.200.$num'"
            $output = Invoke-Command 200.200.200.$num {New-EventLog -LogName System -Source "Timesync Script"}
            $output = Invoke-Command 200.200.200.$num {Write-EventLog -LogName System -Source "Timesync Script" -EntryType Information -EventId 1 -Message "Time was updated"}
        }
    }

}

If everything works, fine, the time should be pushed properly onto the computers and no communication problems should occur with the PLC.


Solution

  • I figured it out, it seemed to occur when the time script pushes the time in the past. The communication seems to be waiting for the time to reach a certain time to resume.

    For example: if time goes back by 10 seconds, the programs communicating will wait 10 seconds before resuming.