好的,我有两个阵列,我正在尝试做的是
array1
(IP范围)中寻找第一个循环的重叠,array2
(IP子网)中查找重叠,然后这里提出的问题是为什么当我运行它时报告重叠的情况并非如此,例如192-168.0.1 - 192.168.0.10(IP范围) 192.168.0.7 - 192.168.0.8(IP范围)相互重叠。但是,10.152.0.100 - 10.152.0.110(IP范围)与任何内容都没有重叠,因此应该报告没有重叠。
$wmi
返回的示例数据将是:
192-168.0.1 - 192.168.0.10 (IP range)
192.168.0.7 - 192.168.0.8 (IP range)
192.168.0.0 (subnet)
192.168.0.15 - 192.168.0.20 (IP range)
10.152.0.100 - 10.152.0.110 (IP range)
192.168.1.100 - 192.168.1.100 (IP range)
代码:
function get_data
{
$wmi = gwmi -Namespace "root\sms\site_XXX" -Class sms_boundary -Filter "boundarytype='3'" | Select-Object -ExpandProperty value #3 = IP Address Range
$Target= @()
foreach($i in $wmi)
{
$target += $i
}
$wm = gwmi -Namespace "root\sms\site_XXX" -Class sms_boundary -Filter "boundarytype='0'" | Select-Object -ExpandProperty value #O = IPSubnet
$Target1= @()
foreach($i1 in $wm)
{
$target1 += $i1
}
foreach($first in $Target)
{
if($Target -contains $first)
{
write-host "Overlap" $first
}
else
{
write-host "No Overlap" $first
}
}
foreach($first1 in $Target1)
{
if($Target -contains $first1)
{
write-host "Overlap" $first1
}
else
{
write-host "No Overlap" $first1
}
}
}
get_data
答案 0 :(得分:0)
你循环“ForEach($ target in $ target)”
然后在该循环中检查$ first是否在$ target中。 当然,因为$ first来自$ target的foreach循环。 我猜你打算检查一下 if($ target1 -contains $ first)?????
此外,这不会真正检查重叠。 但是,脚本只查看确切的记录是否匹配。
10.0.0.0 - 10.0.0.10与10.0.0.7 - 10.0.0.8重叠但是脚本不会检测到它。