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?
-
2writing code would be a good start...Marc B– Marc B2014-03-18 20:38:46 +00:00Commented 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.JoeRod– JoeRod2014-03-18 20:43:36 +00:00Commented 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?TheMadTechnician– TheMadTechnician2014-03-18 20:46:35 +00:00Commented Mar 18, 2014 at 20:46
Add a comment
|
2 Answers
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.