Find duplicate routed allocations
Identify multiple active devices assigned the same IPv4 address within one routing context.
An address needs a context
Separate VRFs can intentionally use overlapping addresses. Within this fictional organisation, each active device must have a unique address in its VRF. There are no approved shared virtual addresses in this dataset.
Group by VRF and Address. Do not add VLAN to that key: two different VLANs in the same VRF do not automatically make duplicate routed allocations acceptable. A same-link ARP conflict is a different question requiring link/broadcast-domain evidence. This exercise reports inventory allocations, not observed ARP behaviour.
Count distinct owners, not repeated rows
The export repeats one assignment. Deduplicate DeviceId inside each group before deciding whether more than one device owns the address. A duplicate row for one device is not a two-device conflict. Ignore retired assignments and return each conflict once.
'D02','D01','D02' | Sort-Object -Unique
Use @(...) around the sorted identifiers so Devices is always an array. The supplied addresses are already in strict canonical form; arbitrary future input should pass through the previous lesson's parser first.
A reported allocation deserves review. Do not infer device reachability, malicious activity, or the exact packet-level impact from an export alone.
Go deeper
Import-Csv '/home/user/allocations.csv' | Group-Object VRF, Address | Select-Object Name, Count
Put it into practice.
Find active allocations shared by more than one distinct DeviceId within the same VRF and Address. Emit VRF, Address, numeric DeviceCount, and a sorted unique Devices array. Ignore retired rows and duplicate copies of the same assignment. VLAN is not part of the conflict key. Order of conflict rows does not matter.
See an explained solution
$rows = @(Import-Csv '/home/user/allocations.csv' | Where-Object State -EQ Active)
foreach ($group in $rows | Group-Object VRF, Address) {
$ids = @($group.Group.DeviceId | Sort-Object -Unique)
if ($ids.Count -gt 1) {
[pscustomobject]@{ VRF=$group.Group[0].VRF; Address=$group.Group[0].Address; DeviceCount=$ids.Count; Devices=$ids }
}
}
Grouping by the routing context keeps legitimate cross-VRF overlap separate while detecting a duplicate across two VLANs in production. Deduplication prevents repeated export rows from inflating the device count.