0

I have a log file with a number of machine names, I'm looking to find the machine name that is listed most. Does anyone have any suggestions where I can get started with this?

3
  • 2
    writing code would be a good start... Commented Mar 18, 2014 at 20:38
  • Yep, thats what I intend on doing looking for any suggestions. Maybe there is a cmdlet that is good for this task. Commented Mar 18, 2014 at 20:43
  • Without knowing what your log looks like it is really impossible to say. Are the computer names the only thing on the line? Are they at the beginning of the line with other text after it? Is it in the middle of a line? Commented Mar 18, 2014 at 20:46

2 Answers 2

3
Get-Content machinesnames.txt | sort | group | sort Count | select Name -last 1
Sign up to request clarification or add additional context in comments.

Comments

0

Consider a file named my.log with the following:

a
b
b
c
c
c

You could run something like:

gc my.log | group-object | sort-object -Property "Count" -Descending | ft -Property ("Name", "Count");

The output is:

Name     Count
----     -----
c        3
b        2
a        1

gc reads each line of your file.

group-object counts each distinct group.

sort-object puts the most common at the top.

ft formats the output into a table. In this case you're interested in machine name and frequency.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.