[ad_1]
As suggested by Santiago Squarzon, simply pipe into Group-Object
:
Get-Content "c:\listip.txt" |
Select-String -Pattern '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' |
Group-Object -NoElement |
Select-Object Count, @{ n='IP'; e="Name" }
Output:
Count IP
----- --
4 1.1.1.1
9 8.8.8.8
The parameter -NoElement
removes the Group
property that is output by default by Group-Object
, but is not needed for counting only.
I’ve added Select-Object
to rename the Name
property to IP
, using a calculated property .
If you’d like to correctly sort the unique IPs (i. e. not string sort, but number by number), you might look at this answer.
[ad_2]