更新时间:2023-11-03 08:36:58
尝试以下方法.应该很近了.
Try the following approach. It should be close.
$lines = Get-Content myfile.txt | Where {$_ -notmatch '^\s+$'}
foreach ($line in $lines) {
$fields = $line -split '\s+'
$ip = $fields[0]
$hosts = $fields[1..3]
foreach ($h in $hosts) {
$hostIP = (Test-Connection $h -Count 1).IPV4Address.ToString()
if ($hostIP -ne $ip) { "Invalid host IP $hostIP for host $h" }
}
}