This topic contains 3 replies, has 2 voices, and was last updated by
March 25, 2018 at 4:32 pm #97056ParticipantPoints: -19Rank: Member
My first post of many i am sure.
I am tidying up years of DHCP reservation abuse across all out DHCP servers before looking to re-architect how we do things.
I have a script that gets all reservations from all servers. The resulting array is grouped on the MAC address and when its output we can see details of machines that have been given multiple reservations BUT its easy to miss the groupings when dealing with thousands of rows.
I would like to add a dummy object in the array between any 2 none identical mac addresses>>
10.259.68.54 10.259.68.0 00-08-74-44-2e-79 p15863. ActiveReservation
10.259.232.239 10.259.232.0 00-08-74-44-ae-29 P09817. ActiveReservation
Is it possible and if it is how would i add a row between the example output from my array?
Cheers for any help you can offer.
March 25, 2018 at 4:40 pm #97058KeymasterPoints: 1,619Rank: Community Hero
So... maybe this is a stupid question, but shouldn't the goal of this to be the computer highlight duplicates, rather than just making it visually easier for a human to do so?
E.g., just have the computer output a list of MAC addresses that do, in fact, occur more than once?
March 25, 2018 at 4:50 pm #97061ParticipantPoints: -19Rank: Member
Hi there. No such thing as a stupid question.. I will happily accept any assistance to identify the duplicates using whatever method.
My mindset was simply to get the duplicates grouped together which i have done but the sheer number is some what overwhelming so i was looking for a way to make differentiating between sets of duplicates in the list.
March 25, 2018 at 4:56 pm #97064KeymasterPoints: 1,619Rank: Community Hero
Yeah, "sheer volume" is why we invented computers to do the hard work :).
Look at PowerShell's Group-Object command. For example, suppose I had a variable $reservations, which contained a collection of objects. Each of those objects as a MACAddress property.
$reservations | Group-Object -Property MACAddress | Where Count -gt 1
Would show you every MACAddress with more than one reservation. With those group objects (which is what Group-Object spits out), you can further manipulate them. For example
Understand that PowerShell is about structured data manipulation, not text manipulation. It can fuss with text, sure, but it's not the shell's strong suit, because text manipulation is a PITA. What you're trying to do is create pretty-looking (for some degree of "pretty") output, which is exactly what PowerShell isn't great at. You have to think less in terms of, "how do I make this look the way I want" and more in terms of "how do I get the shell to do this so I don't have to care what it looks like."
It's why Write-Host is so perniciously evil.
The topic ‘Array with duplicate values on some objects, delimit possible?’ is closed to new replies.