0

I found the below article to help me group a list of IP addresses.

Using Powershell, how can i count the occurrence of each element in an array?

The command I am currently using is:

get-content c:\temp\temp3.txt | group

This would get the following output:

> Count Name                      Group
----- ----                      -----
    3 192.168.1.1             {192.168.1.1, 192.168.1.1, 192.168.1.1}
    3 192.168.1.2             {192.168.1.2, 192.168.1.2, 192.168.1.2}

What command can I use to find all IP's with over a count of 5?

I imagine I would need to put my orignal command as a variable like below:

$groupedoutput get-content c:\temp\temp3.txt | group

Unsure where to go from there. Any help would be appreciated.

Thanks,

S

user3290171
  • 121
  • 1
  • 3
  • 19

1 Answers1

1

In full:

Get-Content -Path c:\temp\temp3.txt  | 
    Group-Object  -NoElement         | 
    Where-Object  { $_.Count -gt 5 } | 
    Select-Object -ExpandProperty Name

In short:

gc c:\temp\temp3.txt | group |? count -gt 5 |% Name

The -NoElement switch means the groups don't gather up all this stuff: {192.168.1.1, 192.168.1.1, 192.168.1.1} , it's not really necessary here but it saves memory if you aren't going to use the grouped items.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87