Invoke-Command阻止辅助网络上的连接

时间:2019-07-12 12:37:09

标签: powershell ethernet invoke-command

我有2台计算机。一个是连接到互联网的数据服务器。该数据服务器每小时都会将TimeSync脚本推送到其他未连接到Internet的计算机。因此,基本上,它们都是通过以太网连接的,但是只有数据服务器基于在线数据才能知道当前时间。第二台计算机是计算机B。

这就是问题所在。

计算机B有2个网卡。一种与数据服务器通信,另一种与PLC(可编程逻辑控制器)通信。而且,每当运行TimeSync脚本时,计算机B和PLC(网卡#2)之间的通信都会在脚本的持续时间内受到干扰,而Windows Registry中不会出现任何错误。

网络1(A):200.200.200.X 网络B(PLC):150.150.150.X

我检查了多个网站,但实际上什么也没发现。

$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"}
        }
    }

}

如果一切正常,则应该将时间正确地拖到计算机上,并且PLC不会出现通讯问题。

1 个答案:

答案 0 :(得分:0)

我想通了,它似乎是在时间脚本将时间推到过去时发生的。通讯似乎正在等待时间才能恢复到特定时间。

例如:如果时间倒退10秒钟,正在通信的程序将等待10秒钟才能恢复。