Author Posts

March 25, 2018 at 4:32 pm

Hi,

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.

Geoff

March 25, 2018 at 4:40 pm

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

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.

Geoff

March 25, 2018 at 4:56 pm

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.