首页 > 解决方案 > Invoke-Command 阻止辅助网络上的连接

问题描述

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

所以这就是问题所在。

计算机 B 有 2 个网卡。一个与数据服务器通信,一个与 PLC(可编程逻辑控制器)通信。并且每当 TimeSync 脚本运行时,计算机 B 和 PLC(网卡 #2)之间的通信都会在脚本执行期间受到干扰,不会在 Windows 注册表中提供任何错误。

网络 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 不会出现通信问题。

标签: powershellethernetinvoke-command

解决方案


我想通了,似乎是时间脚本将时间推过去的时候发生的。通讯似乎是在等待时间到达某个时间才能恢复。

例如:如果时间倒退 10 秒,通信程序将等待 10 秒再恢复。


推荐阅读